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.
Author |
Topic |
Dev@nlkss
134 Posts |
Posted - 2009-02-12 : 22:25:21
|
Hi All,My result set contains 4 columns asPType OnTime Delay MaxDelayDaysP1 NULL 1 2P1 1 NULL 0And My Output sholud contain asPType OnTime Delay MaxDelay AvgP1 1 1 2 2Here 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 takingdenominator 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 MaxDelayAvgFROM TableGROUP BY PType[/code] |
 |
|
|
|
|