Jump to content

FUNCTION COUNT does not exist.


bravo14

Recommended Posts

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
 
Link to comment
https://forums.phpfreaks.com/topic/288184-function-count-does-not-exist/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.