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
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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