Forum » Programiranje » sql max count
sql max count
boss-tech ::
Spodaj najdem prenočišče z največ gosti. v select sem dal count (število gostov) + naziv prenočišča.
Kako lahko zgoraj pri max dobim še naziv? Ker spodnja koda mi vrže error (Error code -1, SQL state 42Y35: Column reference 'NAZIV' is invalid. When the SELECT list contains at least one aggregate then all entries must be valid aggregate expressions.
Line 2, column 1)
Kako lahko zgoraj pri max dobim še naziv? Ker spodnja koda mi vrže error (Error code -1, SQL state 42Y35: Column reference 'NAZIV' is invalid. When the SELECT list contains at least one aggregate then all entries must be valid aggregate expressions.
Line 2, column 1)
#prenocisce z najvec gosti select max(cnt),naziv from ( select count(naziv)as cnt, naziv from prenocisca inner join sobe on sobe.pre_id_prenocisce = prenocisca.id_prenocisce inner join gosti on gosti.sob_id_soba = sobe.id_soba group by naziv )f
WarpedGone ::
#prenocisce z najvec gosti
select naziv
from
(
select count(naziv) as cnt,
naziv
from prenocisca,
sobe,
gosti
where sobe.pre_id_prenocisce = prenocisca.id_prenocisce
and gosti.sob_id_soba = sobe.id_soba
group by naziv
order by 1 desc
)f
where rownum < 2
select naziv
from
(
select count(naziv) as cnt,
naziv
from prenocisca,
sobe,
gosti
where sobe.pre_id_prenocisce = prenocisca.id_prenocisce
and gosti.sob_id_soba = sobe.id_soba
group by naziv
order by 1 desc
)f
where rownum < 2
Zbogom in hvala za vse ribe
boss-tech ::
Order by ne pusti... ko ga odstranim pa dobim: Column 'ROWNUM' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'ROWNUM' is not a column in the target table.
WarpedGone ::
Potem pač Order by prestavi nivo višje.
Očitno tvoja baza ne pozna ROWNUM funkcije.
Očitno tvoja baza ne pozna ROWNUM funkcije.
Zbogom in hvala za vse ribe
dice7 ::
poskusi s tem
SELECT COUNT(p.naziv), p.naziv FROM prenocisca p INNER JOIN sobe s ON s.pre_id_prenocisce = p.id_prenocisce INNER JOIN gosti g ON g.sob_id_soba = s.id_soba GROUP BY p.naziv ORDER BY COUNT(p.naziv) DESC LIMIT 1;
Zgodovina sprememb…
- spremenil: dice7 ()
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | Sql poizvedbaOddelek: Programiranje | 1461 (965) | zgubar |
» | Podatkovne baze - SQL enostavne poizvedbeOddelek: Programiranje | 2053 (1646) | galu |
» | SQL poizvedbaOddelek: Programiranje | 3253 (2598) | awy |
» | sql select stavekOddelek: Programiranje | 1464 (1366) | zavajon |
» | MYSQL vprašanjeOddelek: Programiranje | 1786 (1401) | MrBrdo |