Adott egy adatbázis következő két táblája.
ember (id, nev, varos, szuldat) ↦ ember.csv
auto (rendsz, tulajId, tipus, szin, ar, evjarat) ↦ auto.csv
- Írasd ki a hajdúnánási emberek nevét névsorban!
SELECT nev FROM ember WHERE varos="Hajdúnánás" ORDER BY nev;
SELECT avg(ar) FROM auto WHERE tipus="Honda";
SELECT count(*) FROM auto, ember WHERE auto.tulajId = ember.id AND varos LIKE "Hajdúnánás%";
SELECT varos, count(*) FROM auto, ember WHERE auto.tulajId=ember.id GROUP BY varos ORDER BY varos;
SELECT nev FROM ember, auto WHERE ember.id = auto.tulajId AND tipus="Honda" ORDER BY nev;vagy
SELECT nev FROM ember WHERE id IN (SELECT tulajId FROM auto WHERE tipus="Honda") ORDER BY nev;
SELECT nev FROM ember WHERE id NOT IN (SELECT tulajId FROM auto WHERE tipus="Honda") ORDER BY nev DESC;vagy
(SELECT nev FROM ember) - (SELECT nev FROM ember, auto WHERE ember.id = auto.tulajId AND tipus="Honda") ORDER BY nev DESC;
SELECT count(*) FROM auto WHERE ar < (SELECT avg(ar) FROM auto WHERE tipus="Honda");
SELECT nev FROM ember, auto WHERE ember.id=auto.tulajId AND ar > (SELECT avg(ar) FROM auto WHERE tipus="Honda");
SELECT nev, varos FROM ember, auto WHERE ember.id=auto.tulajId AND ar = (SELECT max(ar) FROM auto WHERE tipus="Honda");
SELECT varos, count(*) AS db FROM auto, ember WHERE ember.id=auto.tulajId AND tipus="Honda" GROUP BY varos HAVING count(*)<3;
SELECT nev, varos, rendsz, tipus FROM ember LEFT OUTER JOIN auto ON ember.id = auto.tulajId;
SELECT e1.nev FROM ember e1, auto a1 WHERE e1.id = a1.tulajId AND a1.ar > (SELECT AVG(a2.ar) FROM ember e2, auto a2 WHERE e2.id = a2.tulajId GROUP BY e2.varos HAVING e1.varos = e2.varos);