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 |
arunkumar09288
Starting Member
1 Post |
Posted - 2010-12-28 : 06:03:06
|
i want similar records of counting from two tables.nw i had this type of result shown below.Brandid toatl2175 951391 80733 501022 49983 432285 43763 39464 381416 172175 171391 152432 152000 13464 8763 8271 61337 62427 61022 51337 5733 41342 4233 3352 3983 32264 31416 213 1142 1206 1233 1271 1275 1384 1552 11680 11924 12000 12081 12285 12432 13504 13615 1from above i want duplicate rows of sum of taotal in one field.for example take 2175 record it is repeated 2 times.so i want 2175 taotal is 95+17=112.how can i achive this?for above result i assumed query like thisselect distinct (od.Brand_Id), total=(count(od.Offer_Id)) from tblm_offers_daily odwhere CategoryPath like 'Cars%' and Geography_Id=4 group by(od.Brand_Id ) unionselect Brand_Id, count(Offer_Id) as total from tblm_offers_historywhere CategoryPath like 'Cars%' and Geography_Id=4group by(Brand_Id) order by total desc |
|
Sachin.Nand
2937 Posts |
Posted - 2010-12-28 : 06:06:58
|
select Brandid,total,sum(Brandid)over(partition by total)as duplicatetotal from yourtablePBUH |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-12-29 : 21:34:22
|
[code]select Brand_Id, total = sum(total)from( select distinct (od.Brand_Id), total=(count(od.Offer_Id)) from tblm_offers_daily od where CategoryPath like 'Cars%' and Geography_Id=4 group by(od.Brand_Id ) union select Brand_Id, count(Offer_Id) as total from tblm_offers_history where CategoryPath like 'Cars%' and Geography_Id=4 group by(Brand_Id)) agroup by Brand_Id order by total desc[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|