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 |
|
eurob
Posting Yak Master
100 Posts |
Posted - 2005-08-30 : 09:36:40
|
| I have two tables:articlesarticle_idweight statusarticle_idsoldI want to have the sum of weight minus the weight for items that are sold. I simplified my example, so the table structure might not make sense, but I just need to know the mechanism on how to to this.select sum(weight) - CASE WHEN s.sold = TRUE then --> how can I select the row that contains the sold item e.g select weight from articles...etc. ELSE 0 END from articles left outer join status s on s.article_id = a.article_id Thanks,robert |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-30 : 09:41:39
|
| Post full table structures with some sample data and your expected resultMadhivananFailing to plan is Planning to fail |
 |
|
|
eurob
Posting Yak Master
100 Posts |
Posted - 2005-08-30 : 10:10:49
|
| ok...articlesarticle_idweightstatusarticle_idsoldArticlesarticle_id.....1weight........10article_id.....2weight........20article_id.....3weight........30statussesarticle_id....2sold.......TRUEso my weight would be 10+20+30 - 20 = 40Thanksrobert |
 |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2005-08-30 : 10:24:53
|
| select sum(a.weight) - sum(c.weight)from articles aleft join status b on a.id = b.article_idleft join articles c on.a.id = c.id and c.sold = true |
 |
|
|
eurob
Posting Yak Master
100 Posts |
Posted - 2005-08-30 : 10:55:49
|
| Thank you,That is simpler than I thought.robert |
 |
|
|
|
|
|