列表

详情


2669. 统计 Spotify 排行榜上艺术家出现次数

表: Spotify

+-------------+---------+ 
| 列名        | 类型    | 
+-------------+---------+ 
| id          | int     | 
| track_name  | varchar |
| artist      | varchar |
+-------------+---------+
id 是该表的主键(具有唯一值的列)。
每行包含 id、track_name 和 artist。

编写解决方案来查找每个艺术家在Spotify排行榜上出现的次数。

返回结果表,其中包含艺术家的名称以及相应的出现次数,按出现次数 降序 排列。如果出现次数相等,则按艺术家名称 升序 排列。

返回结果格式如下所示:

 

示例 1:

输入:
Spotify 表: 
+---------+--------------------+------------+ 
| id      | track_name         | artist     |  
+---------+--------------------+------------+
| 303651  | Heart Won't Forget | Sia        |
| 1046089 | Shape of you       | Ed Sheeran |
| 33445   | I'm the one        | DJ Khalid  |
| 811266  | Young Dumb & Broke | DJ Khalid  | 
| 505727  | Happier            | Ed Sheeran |
+---------+--------------------+------------+ 
输出:
+------------+-------------+
| artist     | occurrences | 
+------------+-------------+
| DJ Khalid  | 2           |
| Ed Sheeran | 2           |
| Sia        | 1           | 
+------------+-------------+ 

解释:"occurrences" 列下按降序列出了出现次数的计数。如果出现次数相同,则艺术家名称按升序排序。

原站题解

去查看

上次编辑到这里,代码来自缓存 点击恢复默认模板
# Write your MySQL query statement below

mysql 解法, 执行用时: 419 ms, 内存消耗: 0 B, 提交时间: 2023-10-15 16:44:37

# Write your MySQL query statement below
select artist, count(id) as occurrences from Spotify group by artist order by occurrences desc, artist asc;

上一题