RANK() 在 mysql 中使用,当我使用子查询获取特定等级的行时,抛出 "Error Code: 1242. Subquery returns more than 1 row"

RANK() used in mysql and when I use a subquery to get rows of a particular rank the "Error Code: 1242. Subquery returns more than 1 row" is thrown

我想使用 rank 函数排列 table,按一个属性划分它并按另一个属性排序,然后显示 Rank 1 的行。

查询:

SELECT *,RANK() OVER (PARTITION BY sales.id ORDER BY sales.time DESC ) as sales_row_num 
FROM sales 
WHERE ( SELECT RANK() OVER (PARTITION BY sales.id ORDER BY sales.time DESC )
        FROM sales ) = 1 ;

Error Code: 1242. Subquery returns more than 1 row

我该怎么办?我还能如何构造我的子查询,因为它是错误的原因?

WITH cte AS (
    SELECT *,
           RANK() OVER (PARTITION BY sales.id ORDER BY sales.time DESC ) as sales_row_num 
    FROM sales 
)
SELECT *
FROM cte
WHERE sales_row_num = 1 ;