poe Posted April 25, 2008 Share Posted April 25, 2008 i have : $db->getOneRow(" SELECT count(*) as cnt, sum(rf) FROM mlb_teamgbg WHERE stc = 22 ORDER BY datestamp DESC LIMIT 5 "); but the count and sum seem to be calculating on the entire db, not just the 5 entries i have a limit of 5 on? Quote Link to comment Share on other sites More sharing options...
fenway Posted April 25, 2008 Share Posted April 25, 2008 You're limiting the number of rows returned, NOT the number of rows considered by the count... if you want the latter, you'll need to derive a table without the aggregate functions, and then use SUM/COUNT on that (untested): SELECT count(*) as cnt, sum(rf) FROM ( SELECT rf FROM mlb_teamgbg WHERE stc = 22 ORDER BY datestamp DESC LIMIT 5 ) AS sub Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 25, 2008 Share Posted April 25, 2008 Beat me to it fenway, but thats the query i had too: SELECT COUNT(*) as cnt,sum(rf) FROM (SELECT rf FROM mlb_teamgbg WHERE stc= 22 ORDER BY datestamp DESC LIMIT 5) as subquery Quote Link to comment Share on other sites More sharing options...
poe Posted April 25, 2008 Author Share Posted April 25, 2008 awsome, thanx guys. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.