| Author |
Topic |
|
v2desperado
Starting Member
2 Posts |
Posted - 2009-01-23 : 14:34:56
|
| I am trying to combine O/P three same queries. Each one runs fine on its own but I cannot figure out how to combine them so all the values are in the one query. Query1select eb.ID,e.Profile, sum(e.Total),sum(e.Price)from Inf as e, details as eb where e.Date between eb.Start and eb.stop and e.Peak='Weekends' and e.Profile=eb.profile group by eb.ID,e.Profileorder by eb.DQuery2select eb.ID,e.Profile, sum(e.Total),sum(e.Price)from Inf as e, details as eb where e.Date between eb.Start and eb.stop and e.Peak='Holiday' and e.Profile=eb.profile group by eb.ID,e.Profileorder by eb.DQuery3select eb.ID,e.Profile, sum(e.Total),sum(e.Price)from Inf as e, details as eb where e.Date between eb.Start and eb.stop and e.Peak='ON' and e.Profile=eb.profile group by eb.ID,e.Profileorder by eb.D output for the individual query is Query1ID,Profile,Total(Hour),Total(Price)---which will give me for weekends----------------------------------1,1001,10,10002,1001,10,1000Query2ID,Profile,Total(Hour),Total(Price)---which will give me for Holiday----------------------------------1,1001,2,1002,1001,2,100Query2ID,Profile,Total(Hour),Total(Price)---which will give me for ON days----------------------------------1,1001,19,30002,1001,19,300But I want some thing likeID,Profile,Total(Hour),Total(Price),Total(Hour),Total(Price),Total(Hour),Total(Price)----------------------------------1,1001,10,1000,2,100,19,3000 2,1001,10,1000,2,100,19,3000 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-01-23 : 15:23:56
|
| [code]select eb.ID,e.Profile ,sum(case when e.peak = 'Weekends' then sum(e.Total) else eo end) as WkndTotal ,sum(case when e.peak = 'Weekends' then sum(e.price) else eo end) as WkndPrice ,sum(case when e.peak = 'Holiday' then sum(e.Total) else eo end) as HolidayTotal ,sum(case when e.peak = 'Holiday' then sum(e.price) else eo end) as HolidayPrice ,sum(case when e.peak = 'ON' then sum(e.Total) else eo end) as ONTotal ,sum(case when e.peak = 'ON' then sum(e.price) else eo end) as ONPricefrom Inf as e inner join details as eb on e.[profile] = [eb.profile]where e.Date between eb.Start and eb.stop group by eb.ID,e.[Profile]order by eb.D[/code]Jim |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-01-23 : 15:26:18
|
oops!inner join details as eb on e.[profile] = [eb.profile]e.[profile] = eb.[profile] |
 |
|
|
v2desperado
Starting Member
2 Posts |
Posted - 2009-01-23 : 16:38:33
|
| Thxs for replying but still have a problemI am getting an error Cannot perform an aggregate function on an expression containing an aggregate or a subqueryand also wat is "eo" |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-01-23 : 23:01:19
|
| I think it is not eo, it is zero and the Query was correct but small modification is thereselect eb.ID,e.Profile ,sum(case when e.peak = 'Weekends' then (e.Total) else 0 end) as WkndTotal ,sum(case when e.peak = 'Weekends' then (e.price) else 0 end) as WkndPrice ,sum(case when e.peak = 'Holiday' then (e.Total) else 0 end) as HolidayTotal ,sum(case when e.peak = 'Holiday' then (e.price) else 0 end) as HolidayPrice ,sum(case when e.peak = 'ON' then (e.Total) else 0 end) as ONTotal ,sum(case when e.peak = 'ON' then (e.price) else 0 end) as ONPricefrom Inf as e inner join details as eb on e.[profile] = [eb.profile]where e.Date between eb.Start and eb.stop group by eb.ID,e.[Profile]order by eb.ID |
 |
|
|
|
|
|