bravo14 Posted May 2, 2014 Share Posted May 2, 2014 Hi I am trying to a query that has countif in the query is to find the top 8 riders based on ponts scored then number of wins (where points = 3), number of 2nd places (points = 2 etc) SELECT COUNT( `points` ) AS `rides`, SUM( `points` ) AS `pts`, COUNT (IF(`points`=3,1,0)) AS `wins`, COUNT (IF(`points`=2,1,0)) AS `2`, COUNT (IF(`points`=1,1,0)) AS `1`, COUNT (IF(`points`=0,1,0)) AS `0`, rider_name FROM tbl_heat WHERE card_id = $card GROUP BY `rider_name` ORDER BY pts DESC LIMIT 8 Quote Link to comment https://forums.phpfreaks.com/topic/288184-function-count-does-not-exist/ Share on other sites More sharing options...
fastsol Posted May 2, 2014 Share Posted May 2, 2014 You can't have a space after the word COUNT in the query string, it must be COUNT() not COUNT () Quote Link to comment https://forums.phpfreaks.com/topic/288184-function-count-does-not-exist/#findComment-1477950 Share on other sites More sharing options...
Barand Posted May 2, 2014 Share Posted May 2, 2014 ... and in this case you need SUM and not COUNT SELECT COUNT( `points` ) AS `rides` , SUM( `points` ) AS `pts` , SUM(IF(`points`=3,1,0)) AS `wins` , SUM(IF(`points`=2,1,0)) AS `second` , SUM(IF(`points`=1,1,0)) AS `third` , SUM(IF(`points`=0,1,0)) AS `unplaced` , rider_name FROM tbl_heat WHERE card_id = $card GROUP BY `rider_name` ORDER BY pts DESC LIMIT 8 Quote Link to comment https://forums.phpfreaks.com/topic/288184-function-count-does-not-exist/#findComment-1477951 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.