我不知道我的语法哪里错了。我需要根据 invoice_total ``` select * from ( select vendor_id, invoice_total, dense_rank () over(partition by vendor_id order by invoice_total asc) as ranking from invoices) a1
select *
from (
select vendor_id, invoice_total,
dense_rank () over(partition by vendor_id order by invoice_total asc)
as ranking
from invoices) a1
where a1.ranking = 1;
select i.*
from invoices i
where (i.vendor_id, i.invoice_total) in
(select i2.vendor_id, max(i2.invoice_total)
from invoices i2
group by i2.vendor_id
);
2条答案
按热度按时间bsxbgnwa1#
添加
where a1.ranking = 1
对于sql的外部部分:w7t8yxp52#
mysql只支持
dense_rank()
在版本8+中。始终可以使用相关子查询:这假设“顶级供应商”指的是最大的总数,这与您的sql相反。
还有其他的表达方式。我也喜欢在mysql中使用元组: