Advertisement
Sofe1204

Untitled

Mar 29th, 2022
674
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select k.klient_id, k.k_ime, b.b_naziv,
  2. count(t.trans_br) as br_transakcii
  3. from klienti k
  4. join
  5.   (
  6.     select s.klient_id
  7.     from smetki s
  8.       left join
  9.       (
  10.         select kk.klient_id,
  11.         count(distinct q1.tipsmetka_sifra) tipsmetki_broj
  12.         from klienti kk
  13.         left join
  14.           (
  15.             select ol.klient_id, ol.smetka_br, ss.tipsmetka_sifra
  16.             from ovlasteni_lica ol
  17.             left join smetki ss on ss.smetka_br = ol.smetka_br
  18.             UNION
  19.             select s.klient_id, s.smetka_br, s.tipsmetka_sifra
  20.             from smetki s
  21.           ) q1 on q1.klient_id = kk.klient_id
  22.         group by 1
  23.       ) q2 on q2.klient_id = s.klient_id
  24.     group by s.klient_id,q2.tipsmetki_broj
  25.     having (select count(*) from tipovi_smetki) = q2.tipsmetki_broj
  26.   ) q3 on q3.klient_id=k.klient_id
  27.  
  28. left join smetki s on s.klient_id = k.klient_id
  29. left join banki b on b.banka_id = s.banka_id
  30. left join transakcii t on t.smetka_br = s.smetka_br
  31. group by 1,2,3
Advertisement
RAW Paste Data Copied
Advertisement