USE `Kosidasdb`;

SELECT AVG(gehalt) FROM mitarbeiter
WHERE plzid = 6;

SELECT plzid, AVG(gehalt) FROM mitarbeiter
GROUP BY plzid;

SELECT plzid, geschlecht, COUNT(*) FROM mitarbeiter
GROUP BY plzid, geschlecht;

SELECT MAX(preis), AVG(preis), MIN(preis) FROM artikel
GROUP BY kategorie;

SELECT kategorie, COUNT(*) FROM artikel
GROUP BY kategorie
HAVING COUNT(*) > 5;

SELECT kategorie, COUNT(*) FROM artikel
WHERE preis > 50
GROUP BY kategorie;

SELECT kategorie, COUNT(*) FROM artikel
WHERE preis > 50
GROUP BY kategorie
HAVING COUNT(*) > 2;

SELECT plzid, AVG(gehalt) FROM mitarbeiter
GROUP BY plzid
HAVING COUNT(*) >= 2;

SELECT kategorie, AVG(Preis) FROM artikel
GROUP BY kategorie
HAVING AVG(Preis) > 30;

SELECT bestellid, COUNT(*) FROM posten
GROUP BY bestellid;

SELECT kategorie, COUNT(DISTINCT farbe) FROM artikel
GROUP BY kategorie
ORDER BY COUNT(DISTINCT farbe) DESC
LIMIT 1;

SELECT kategorie, COUNT(*) FROM artikel
GROUP BY kategorie
HAVING (SUM(preis) < 600) AND (COUNT(*) < 20);