我有一个表,表中包含order_id、customer id、product id列
我想对product_id 257销量前5名的product_id进行排名。
是否必须为与product_id 257一起销售的所有产品创建一个新列?然后对他们进行排名?
或者有没有一种方法来过滤数据?
请帮我指出正确的方向!
发布于 2020-06-07 00:09:48
此查询为:
用于获得正确的orders.
在SQL中,这看起来像:
select t.product_id, count(*)
from t
where exists (select 1
from t t2
where t2.order_id = t.order_id and t2.product_id = 257
) and
t.product_id = 257
group by t.product_id
order by count(*) desc
fetch first 5 rows only;https://stackoverflow.com/questions/62234417
复制相似问题