我使用ROW_NUMBER按销售额排名国家。查询如下所示
<Input onChange={e => alert(e.target.value)} />
由于某种原因,所有国家的排名都是一个。
答案 0 :(得分:3)
如果按COUNTRY
进行分区,则row_number将重置为1
SELECT country,
SUM(sales) AS sales,
ROW_NUMBER() OVER (ORDER BY SUM(sales) DESC) AS 'rank'
FROM table
GROUP BY country
ORDER BY sales DESC