预警,我是一个新手,所以要温和。我需要从一组值中得到 qty 的SUM,然后是前5个MAX sum qty 从那个名单。但是我需要从最终列表中省略一个NULL值。
答案 0 :(得分:1)
我会在没有子查询的情况下执行此操作:
select game_name, sum(qty) AS total
from sales
where game_name is not null
group by game_name
order by total desc
limit 5;
答案 1 :(得分:0)
试试这个:
SELECT game_name,
max(total) AS total
FROM ( select game_name,
sum(qty) AS total
FROM sales
GROUP BY game_name
) AS RANK
where game_name is not null
group by game_name
order by total desc limit 5 ;
它将删除任何null
游戏,按总降序排序,它会为您提供前5行。