Can not find a way to bypass the Group

The following query runs as is, but only because I have included IntervForcl, IsSpecial , in the group by clause. I don't want group by these things, that month. I have no idea how to write this query, do what I want, I tried everything. Any suggestion would be appreciated.

The end result is supossed to look something like this:

PostedDate RushMargin NonRushMargin InteriorMargin

2013.01 65.4% 42% 21.5%

2013.02 62.7% 43.5% 32%

2013.03 67.3% 41.1% 29.8%

SELECT CONVERT (varchar (7), APPostedWhen, 102) AS [PostedDate].

[InteriorMargin] = BOX

WHEN intervforcl = 'k' THEN CAST (((APAMOUNT) AVG / AVG (ARAMOUNT)) * 100 AS DECIMAL (12,2))

END,

[RushMargin] = BOX

WHEN IsSpecial = '1' CAST (((APAMOUNT) AVG / AVG (ARAMOUNT)) * 100 AS DECIMAL (12,2))

END,

[NonRushMargin] = BOX

WHEN IsSpecial <>'1' THEN CAST (((APAMOUNT) AVG / AVG (ARAMOUNT)) * 100 AS DECIMAL (12,2))

END

Inspections

WHERE DATEDIFF (MONTH, APPostedWhen, SYSDATETIME ()) < 6 AND ARAMOUNT > 0 AND APAMOUNT > 0

GROUP OF CONVERT (varchar (7), APPostedWhen, 102)IntervForcl, IsSpecial

ORDER BY [PostedDate]

It is a forum for oracle pl/sql.

What you think you have TSQL.

However we need conditions case inside aggregate functions, I guess.

as

CAST ((AVG (affaire quand intervforcl = 'k' alors fin APAMOUNT) / AVG (case...)) (ARAMOUNT)) * 100 AS DECIMAL (12,2))

and so on.

Be careful on the way in which the aggregate function deal with NULL values.

Tags: Database

Similar Questions

Maybe you are looking for