How would I query top 3 songs played from user? userid and song_name is char(255)
Here is the description of the table:
+-----------+-----------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-----------+------+-----+-------------------+-------+
| userid | char(255) | YES | | NULL | |
| song_name | char(255) | YES | | NULL | |
| timestamp | timestamp | NO | | CURRENT_TIMESTAMP | |
+-----------+-----------+------+-----+-------------------+-------+
Here is sample of what a table would look like:
+--------+-----------+---------------------+
| userid | song_name | timestamp |
+--------+-----------+---------------------+
| 123 | A | 2017-01-04 01:35:41 |
| 123 | B | 2017-01-04 01:37:57 |
| 123 | B | 2017-01-04 01:38:32 |
| 123 | B | 2017-01-04 01:38:42 |
| 123 | C | 2017-01-04 01:38:46 |
| 123 | D | 2017-01-04 01:38:50 |
| 123 | E | 2017-01-04 01:38:54 |
| 123 | E | 2017-01-04 01:38:59 |
| 123 | A | 2017-01-04 01:39:03 |
| 123 | E | 2017-01-04 01:39:20 |
I changed the song_names to letters for you to better understand. A top song really would be how many time a song_name correspond to the userid.
Current code:
SELECT userid, GROUP_CONCAT(DISTINCT song_name
ORDER BY song_name)
top_songs
FROM sampleTable3
GROUP BY userid;
How would I alter it that it would print out the top 3 songs order by most played?
My question is asking how many time a specific value corresponds to userid.