Subtraction problem?

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 ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-21-2007
Tom
 
Posts: n/a
Default Subtraction problem?

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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:51 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0