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 |
|
cutepraba
Yak Posting Veteran
53 Posts |
Posted - 2012-07-21 : 12:30:11
|
| I have tables called job and jobhistory and i need to get sum of total from both with same where class. All the fields are same in both table.like this:select sum(total) from jobhistory where jobdate = '7/2/2012' and id=35+select sum(total) from job where jobdate = '7/2/2012' and id=35Is there any optimized query to get that?____________Praba |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-21 : 12:35:31
|
| [code]select j.id,j.jobdate,sum(j.total) + jh.histtotalfrom job jinner join (select id,jobdate,sum(total) as histtotalfrom jobhistory group by id,jobdate)jhon j.jobdate = jh.jobdateand j.id = jh.idgroup by j.id,j.jobdate,jh.histtotal[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
bitsmed
Aged Yak Warrior
545 Posts |
Posted - 2012-07-22 : 16:55:19
|
| [code]select sum(a.total) as total from (select sum(total) as total from jobhistory where jobdate = '7/2/2012' and id=35 union all select sum(total) as total from job where jobdate = '7/2/2012' and id=35 ) as a[/code] |
 |
|
|
|
|
|