I want to get the row with the maximum value on a column. I my case I want to ptint only X that has 31. This is my code and also the output.
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
But it's a wrong approach, for example without the X , Audi or BMW has 7 but my select will print just the first Audi. So it's another method to get the maximum value