This is a discussion on Subtraction problem? within the MySQL Database forums, part of the Database Forums category; I must be doing something wrong here, but I can't for the life of me figure it out. SELECT ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I must be doing something wrong here, but I can't for the life of me
figure it out. SELECT gifts.*, count(distinct bookmarks.id) as bmcount, (select sum(have_it) from bookmarks as b1 where b1.gift_id=gifts.id) as c_count_haveit, ( (count(distinct bookmarks.id)) - (select sum(have_it) from bookmarks as b2 where b2.gift_id=gifts.id)) as c_count_wantit FROM bookmarks, gifts WHERE bookmarks.gift_id = gifts.id group by gifts.id This returns: bmcount of 1 c_count_haveit of 1 c_count_wantit of 1 But that should be impossible, as far as I can tell. The line that determines the value of c_count_wantit is just subtracting bmcount from c_count_haveit. So, shouldn't it be zero? If I replace either of the sides of the equation with 1, I get the zero I expected. So, both seem to be returning one, but when I put them together and subtract one from one - I get one! Anyone see what I'm doing wrong? Many thanks, Tom Lianza |