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 |
|
confuzed04
Starting Member
39 Posts |
Posted - 2007-05-25 : 11:56:56
|
| I have the following query and I am wanting to get the results by date. Please advise.SELECT COUNT(UniqueCallID), VoiceCallDetailRecord.[Type], SUM(PaidBalCost), SUM(BonusBalCost), SUM(FreeMsgCost), SUM(ceiling((Cast(DurationSeconds as Decimal)/60))) as MinutesFROM VoiceCallDetailRecordWHERE VoiceCallDetailRecord.[Type] IN ('MOSMS','FreeMTSMS')AND CallDate Between '01/01/2007' and '02/01/2007'GROUP BY VoiceCallDetailRecord.[Type] and GROUP BY dateadd(day, datediff(day, 0, CallDate), 0)UNIONSELECT COUNT(UniqueCallID), ZeroChargeVCDRecord.[Type], SUM(PaidBalCost), SUM(BonusBalCost), SUM(FreeMsgCost), SUM(ceiling((Cast(DurationSeconds as Decimal)/60))) as MinutesFROM ZeroChargeVCDRecordWHERE ZeroChargeVCDRecord.[Type] IN ('MOSMS','FreeMTSMS')AND CallDate Between '01/01/2007' and '02/01/2007'GROUP BY ZeroChargeVCDRecord.[Type] |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
confuzed04
Starting Member
39 Posts |
Posted - 2007-05-25 : 12:24:06
|
| Yeah. I tried doing the same thing to this one and it gave me an error. It doesn't like the two Group By statements. The 'and' bothers it for some reason. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-05-25 : 19:18:21
|
you have the syntax wrong. You cannot have 2 GROUP BY statementGROUP BY VoiceCallDetailRecord.[Type] and GROUP BY, dateadd(day, datediff(day, 0, CallDate), 0) KH |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
confuzed04
Starting Member
39 Posts |
Posted - 2007-05-29 : 14:48:14
|
| Thank you so much khtan! You have been a big help! That worked. So you can never have two group by statements? Why can you not use and, yet you can with a WHERE statement? Just curious. Thanks again for all your help! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-05-29 : 23:50:12
|
you cant use and in group by as you use in Where clauseAs I specified, learn sql MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|