我想获取列上具有最大值的行。我的情况我只想说明有31的X.这是我的代码,也是输出。
create temp view Private(marca) as
Select a.marca, count(*) as totaleNoleggi, count(distinct a.targa) as totaleAuto, sum(extract(hour from (n.fine-n.inizio))) as totOre
from auto a join noleggio n on a.targa=n.targa
group by a.marca;
select marca, totOre
from Private
group by marca,totore
order by totore desc
limit 1;
marca totalenoleggi totaleauto totore
1 Audi 1 1 7
2 BMW 5 4 7
3 VW 2 1 1
4 X 2 1 31
marca totore
1 X 31
但这是一个错误的方法,例如没有X,奥迪或宝马有7,但我的选择将打印出第一辆奥迪。所以它是获得最大值的另一种方法
答案 0 :(得分:1)
我觉得ALL
构造在这里很有用
SELECT marca, totOre
FROM Private
WHERE totore >= ALL(select totore from private)
答案 1 :(得分:0)
您可以使用子查询
select marca, totOre
from Private
where totore = (select max(totore) from private)
希望它会有所帮助。