-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL cvičení: zakázky v kontextu #239
Comments
A smlouvy v kontextu. Bohužel teda vzhledem ke způsobu nahrávání dat to tam máme trochu přeházený a bez zadavatele (protože ani nevíme, kdo to zadal). with organy as (
SELECT
jmeno, prijmeni, narozeni, string_agg(distinct nazev_organu_cz, ', ') as org
FROM
psp.poslanci_osoby os
INNER JOIN psp.poslanci_zarazeni zar on zar.id_osoba = os.id_osoba
INNER JOIN psp.poslanci_organy org on org.id_organ = zar.id_of
where cl_funkce = 0
group by 1, 2, 3
), osoby as (
SELECT
pos.jmeno, pos.prijmeni, pos.narozeni, pos.org, ang.funkce, ang.ico, ang.datum_zapis, ang.datum_vymaz
FROM
organy pos
inner join justice.angazovane_osoby ang on lower(ang.jmeno) = lower(pos.jmeno) and lower(ang.prijmeni) = lower(pos.prijmeni) and pos.narozeni = ang.datum_narozeni
)
SELECT
osoby.jmeno, osoby.prijmeni, osoby.org, osoby.ico, osoby.datum_zapis, osoby.datum_vymaz, uc.nazev as dodavatel_nazev, osoby.funkce,
sml.*,
uc.*
FROM smlouvy.smlouvy sml
INNER JOIN smlouvy.ucastnici uc on sml.id_verze = uc.smlouva
INNER JOIN osoby on osoby.ico = uc.ico
WHERE sml.cas_zverejneni > now() - interval '6 month'
and (osoby.datum_vymaz is null OR osoby.datum_vymaz > sml.datum_uzavreni)
AND COALESCE(sml.hodnota_s_dph, hodnota_bez_dph) > 1e8
limit 100 |
A ReD (rozšířil jsem to časové období, protože data maj zpoždění) with organy as (
SELECT
jmeno, prijmeni, narozeni, string_agg(distinct nazev_organu_cz, ', ') as org
FROM
psp.poslanci_osoby os
INNER JOIN psp.poslanci_zarazeni zar on zar.id_osoba = os.id_osoba
INNER JOIN psp.poslanci_organy org on org.id_organ = zar.id_of
where not cl_funkce
group by 1, 2, 3
), osoby as (
SELECT
pos.jmeno, pos.prijmeni, pos.narozeni, pos.org, ang.funkce, ang.ico, ang.datum_zapis, ang.datum_vymaz
FROM
organy pos
inner join justice.angazovane_osoby ang on lower(ang.jmeno) = lower(pos.jmeno) and lower(ang.prijmeni) = lower(pos.prijmeni) and pos.narozeni = ang.datum_narozeni
)
SELECT
osoby.jmeno, osoby.prijmeni, osoby.org, osoby.ico, osoby.datum_zapis, osoby.datum_vymaz, prijemce.obchodni_nazev, osoby.funkce,
dotace.podpis_datum, castka_rozhodnuta, dotace.nazev, rozhodnuti.dotace_poskytovatel,
dotace.*,
prijemce.*,
rozhodnuti.*
FROM
red.dotace
INNER JOIN red.prijemce using(id_prijemce)
INNER JOIN red.rozhodnuti using(id_dotace)
INNER JOIN osoby on osoby.ico = prijemce.ico
WHERE
-- dotace.podpis_datum > now() - interval '12 months'
rok_rozhodnuti = 2022
and osoby.datum_zapis < dotace.podpis_datum
and (osoby.datum_vymaz is null OR osoby.datum_vymaz > dotace.podpis_datum)
AND rozhodnuti.castka_rozhodnuta > 1e6
ORDER by podpis_datum desc
LIMIT 100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: