obliczanki.sql 1.95 KB
-- nieadj to 20, 21, 22, 23

-- SGJP
SELECT
    pos,
    CASE WHEN l_id_od IS null THEN 'aff'
    ELSE 'neg' END AS nie,
    count(*)
FROM leksemy l LEFT OUTER JOIN odsylacze o
        ON (l.id = o.l_id_od AND typods_id IN (20, 21, 22, 23))
WHERE slownik = 'SGJP'
GROUP BY pos, nie;

-- wspólne (złe! leksem się liczy tyle razy, ile razy jest w słowniku)
SELECT
    pos,
    CASE WHEN l_id_od IS null THEN 'aff'
    ELSE 'neg' END AS nie,
    count(*)
FROM leksemy l JOIN leksemy_w_slownikach s1
        ON (l.id = s1.l_id)
    JOIN leksemy_w_slownikach s2
        ON (l.id = s2.l_id)
    LEFT OUTER JOIN odsylacze o
        ON (l.id = o.l_id_od AND typods_id IN (20, 21, 22, 23))
WHERE s1.slownik = 'SGJP' AND s2.slownik = 'Morfologik'
GROUP BY pos, nie;

-- razem
SELECT
    pos,
    CASE WHEN l_id_od IS null THEN 'aff'
    ELSE 'neg' END AS nie,
    count(*)
FROM leksemy l LEFT OUTER JOIN odsylacze o
        ON (l.id = o.l_id_od AND typods_id IN (20, 21, 22, 23))
WHERE slownik IN ('SGJP', 'Morfologik')
GROUP BY pos, nie;

-- tylko Morfologik
SELECT
    pos,
    CASE WHEN l_id_od IS null THEN 'aff'
    ELSE 'neg' END AS nie,
    count(*)
FROM leksemy l LEFT OUTER JOIN odsylacze o
        ON (l.id = o.l_id_od AND typods_id IN (20, 21, 22, 23))
WHERE slownik = 'Morfologik'
GROUP BY pos, nie;

-- tylko SGJP (wspólne bez not)
SELECT
    pos,
    CASE WHEN l_id_od IS null THEN 'aff'
    ELSE 'neg' END AS nie,
    count(*)
FROM leksemy l LEFT OUTER JOIN odsylacze o
        ON (l.id = o.l_id_od AND typods_id IN (20, 21, 22, 23))
WHERE slownik = 'SGJP' AND NOT exists(SELECT
                                          id
                                      FROM leksemy_w_slownikach
                                      WHERE l_id = l.id AND
                                            slownik = 'Morfologik')
GROUP BY pos, nie;

-- Morfologik wg statusów
SELECT
    pos,
    status,
    count(*)
FROM leksemy l
WHERE slownik = 'Morfologik'
GROUP BY pos, status
ORDER BY pos, status;