Jump to content

Get most frequent data in column


Kingskin

Recommended Posts

Hi,

 

My db table (episode_result) has these columns:

 

player_id

position

 

I'm trying to find which player_id occurs most often where position = 1.

Eg, if i've got:

 

player_id | position
          |
Bill      |     1
Bill      |     1
Ben       |     1
Bill      |     3
Ben       |     2
Bill      |     1

 

I want to return 'Bill'

 

I've got this code:

 

SELECT TOP 1 player_id
FROM (SELECT COUNT(*) AS myNewColumn, player_id
FROM episode_result
WHERE position = 1
GROUP BY player_id) DERIVEDTBL
ORDER BY myNewColumn DESC";

 

But unfortunately it doesn't work. Can anyone help me out with this please?

Link to comment
Share on other sites

untested

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] COUNT(position) AS myNewColumn, player_id

FROM episode_result WHERE position = 1

GROUP BY player_id ORDER BY myNewColumn DESC LIMIT 1 [!--sql2--][/div][!--sql3--]

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.