Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 SQL server

Author  Topic 

Dev@nlkss

134 Posts

Posted - 2009-02-12 : 22:25:21
Hi All,
My result set contains 4 columns as

PType OnTime Delay MaxDelayDays
P1 NULL 1 2
P1 1 NULL 0

And My Output sholud contain as

PType OnTime Delay MaxDelay Avg
P1 1 1 2 2

Here is an explanation:
MaxDelay:shows how many days it got delayed.
AVG: MaxDelay/Delay count i.e 2/1 (excludes Ontime)
and finally i have to group by PType.

But when i execute Query am getting Avg as 2 i.e its taking
denominator count as both Ontime and Delay but where in it has to take only Delay Record count.

Its urgent.
Thanks for any help.

Satya

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-13 : 01:35:23
[code]
SELECT PType,MAX(OnTime),MAX(Delay),Avg(CASE WHEN Delay=1 THEN MaxDelayDays ELSE NULL END) AS MaxDelayAvg
FROM Table
GROUP BY PType
[/code]
Go to Top of Page
   

- Advertisement -