Untitled
Guest 28 2nd Jan, 2025
SELECT TOP 1 g.nazwa AS tytul_gry, COUNT(o.ocena) AS liczba_ocen
FROM oceny o
JOIN gry g ON o.id_gry = g.id_gry
GROUP BY g.nazwa
ORDER BY liczba_ocen DESC;
SELECT g.nazwa AS tytul_gry, ROUND(AVG(o.ocena), 2) AS srednia_ocen
FROM oceny o
JOIN gry g ON o.id_gry = g.id_gry
WHERE g.kategoria = 'imprezowa'
GROUP BY g.nazwa;
SELECT COUNT(DISTINCT o.id_gracza) AS liczba_graczy
FROM oceny o
WHERE o.id_gracza NOT IN (
SELECT DISTINCT o1.id_gracza
FROM oceny o1
WHERE o1.stan = 'posiada'
)
AND o.ocena IS NOT NULL;
WITH KategorieWiekowe AS (
SELECT
g.nazwa AS tytul_gry,
CASE
WHEN gr.wiek <= 19 THEN 'juniorzy'
WHEN gr.wiek BETWEEN 20 AND 49 THEN 'seniorzy'
ELSE 'weterani'
END AS kategoria,
COUNT(o.ocena) AS liczba_ocen
FROM oceny o
JOIN gry g ON o.id_gry = g.id_gry
JOIN gracze gr ON o.id_gracza = gr.id_gracza
GROUP BY g.nazwa,
CASE
WHEN gr.wiek <= 19 THEN 'juniorzy'
WHEN gr.wiek BETWEEN 20 AND 49 THEN 'seniorzy'
ELSE 'weterani'
END
),
MaksOceny AS (
SELECT kategoria, MAX(liczba_ocen) AS max_oceny
FROM KategorieWiekowe
GROUP BY kategoria
)
SELECT k.kategoria, k.liczba_ocen AS max_oceny, k.tytul_gry
FROM KategorieWiekowe k
JOIN MaksOceny m ON k.kategoria = m.kategoria AND k.liczba_ocen = m.max_oceny
ORDER BY k.kategoria, k.tytul_gry;
To share this paste please copy this url and send to your friends
RAW Paste Data