Garayed.com  

Go Back   Garayed.com > mySQL
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-21-2007, 03:22 AM
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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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

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



All times are GMT. The time now is 12:55 AM.




LinkBacks Enabled by vBSEO 3.0.0 © 2007, Crawlability, Inc.