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 |
|
Kotti
Posting Yak Master
129 Posts |
Posted - 2008-12-24 : 04:30:39
|
| Hi Friends,I used this query select (count(c.PostId)) as TotalComments from ez_post as p inner join ez_comment as c ON p.PostId=c.PostId where p.BlogId=1 group by c.PostIdI got result like this213But I need sum of that rows(2+1+3).may i know how to get this? |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-12-24 : 04:41:26
|
| hi try thisselect count(c.PostId) as TotalComments into #temp from ez_post as p inner join ez_comment as cON p.PostId=c.PostIdwhere p.BlogId=1 group by c.PostIdselect sum(TotalComments) as TotalComments from #temp |
 |
|
|
Kotti
Posting Yak Master
129 Posts |
Posted - 2008-12-24 : 06:07:10
|
| What is #temp?My result is not static ,it will change .Any posibility to do in another way? |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-12-24 : 06:10:58
|
quote: Originally posted by Kotti What is #temp?My result is not static ,it will change .Any posibility to do in another way?
#temp is a temporary table. I think no problem with it. U can use it. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-12-24 : 07:28:33
|
| No need of temporary tableselect sum(TotalComments) as TotalComments from(select (count(c.PostId)) as TotalComments from ez_post as p inner join ez_comment as cON p.PostId=c.PostIdwhere p.BlogId=1 group by c.PostId) as tMadhivananFailing to plan is Planning to fail |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-12-24 : 07:58:55
|
| Can't you directly use like this?select sum(c.PostId) as TotalComments from ez_post as p inner join ez_comment as cON p.PostId=c.PostIdwhere p.BlogId=1 |
 |
|
|
|
|
|