时间:2021-07-01 10:21:17 帮助过:19人阅读
select type, variety, price
from fruits
where (
select count(*) from fruits as f
where f.type = fruits.type and f.price < fruits.price
) <= 1;
select count(*) from fruits as f
where f.type = fruits.type and f.price < fruits.price
即,在apple这个类别中,价格比2.79还要低的元组的数量。
select count(*) from fruits as f
where f.type = apple and f.price < 2.79
可以知道,apple中价格低于2.79的只有fuji这个元组,即值为1,满足子条件<=1的条件,所以该字段会被输出。
select type, variety, price
from fruits
where (
select count(*) from fruits as f
where f.type = apple and f.price < 2.79
) <= 1;
select type, variety, price
from fruits
where (
select count(*) from fruits as f
where f.type = fruits.type and f.price < fruits.price
) <= 1
order by fruits.type, fruits.price
如何在MySQL中实现组内前几名的输出
标签:照相 color 链接 pre 元组 idt 使用 应该 技术