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? Link to comment https://forums.phpfreaks.com/topic/102934-solved-sum-count-limit/ 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 Link to comment https://forums.phpfreaks.com/topic/102934-solved-sum-count-limit/#findComment-527334 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 Link to comment https://forums.phpfreaks.com/topic/102934-solved-sum-count-limit/#findComment-527342 Share on other sites More sharing options...
poe Posted April 25, 2008 Author Share Posted April 25, 2008 awsome, thanx guys. Link to comment https://forums.phpfreaks.com/topic/102934-solved-sum-count-limit/#findComment-527368 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.