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 |
|
rocco2008
Yak Posting Veteran
63 Posts |
Posted - 2008-10-31 : 07:40:43
|
| Hi I have two queries and like to sum up the results. My query looks like thisSelect Count(*), a, b, AVG(size)from Table1where c in ('monday','tuesday','wednesday')AND ISBN = '12345'group by a, border by aSelect Count(*), a, b, AVG(size)from Table2where c in ('monday','tuesday','wednesday')AND ISBN = '12345'group by a, border by aresults look like this:69 A 0 33290.3333333333363593 B 0 5019.22961313665471128 A 1 3194.4592198581558247 A 0 2617.47368421052622112 B 0 3525.939393939394277 A 1 2624.4693140794225I would now like to sum up the results for A,0 and get it printed out (eg 69 + 247 = 316)I tried to put a union in between those queries above, but I get an error message. Any ideas?Tnx |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-31 : 08:26:42
|
| select sum(counting) as counting,a,b,avg_size from(Select Count(*) as counting, a, b, AVG(size) as avg_sizefrom Table1where c in ('monday','tuesday','wednesday')AND ISBN = '12345'group by a, bunion allSelect Count(*), a, b, AVG(size)from Table2where c in ('monday','tuesday','wednesday')AND ISBN = '12345'group by a, b) as torder by aMadhivananFailing to plan is Planning to fail |
 |
|
|
rocco2008
Yak Posting Veteran
63 Posts |
Posted - 2008-10-31 : 11:01:34
|
| awesome tnx |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-01 : 02:50:48
|
quote: Originally posted by rocco2008 awesome tnx
You are welcome MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|