Advertisement
Sofe1204

Untitled

Mar 29th, 2022
833
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select k.k_ime,k.k_embg,godina,
  2. (select count(distinct tr.trans_br || '-' || tr.smetka_br )
  3. from transakcii as tr
  4.  join smetki as s on s.smetka_br=tr.smetka_br
  5.  where extract(quarter from tr.datum)=1 and
  6.    extract(year from tr.datum)=god.godina
  7.     and s.klient_id=k.klient_id
  8. ) as br_trans_trim_1,
  9. (select count(distinct tr.trans_br || '-' || tr.smetka_br )
  10. from transakcii as tr
  11.  join smetki as s on s.smetka_br=tr.smetka_br
  12.  where extract(quarter from tr.datum)=2 and
  13.    extract(year from tr.datum)=god.godina
  14.     and s.klient_id=k.klient_id
  15. ) as br_trans_trim_2,
  16. (select count(distinct tr.trans_br || '-' || tr.smetka_br )
  17. from transakcii as tr
  18.  join smetki as s on s.smetka_br=tr.smetka_br
  19.  where extract(quarter from tr.datum)=3 and
  20.    extract(year from tr.datum)=god.godina
  21.     and s.klient_id=k.klient_id
  22. ) as br_trans_trim_3,
  23. (select count(distinct tr.trans_br || '-' || tr.smetka_br )
  24. from transakcii as tr
  25.  join smetki as s  on s.smetka_br=tr.smetka_br
  26.  where extract(quarter from tr.datum)=4 and
  27.    extract(year from tr.datum)=god.godina
  28.     and s.klient_id=k.klient_id
  29. ) as br_trans_trim_4,
  30. (select avg(tr.iznos)
  31. from transakcii as tr
  32.  join smetki as s on s.smetka_br=tr.smetka_br
  33.  where extract(quarter from tr.datum)=1 and
  34.    extract(year from tr.datum)=god.godina
  35.     and s.klient_id=k.klient_id
  36. ) as prosek_iznos_trim_1,
  37. (select avg(tr.iznos)
  38. from transakcii as tr
  39.  join smetki as s on s.smetka_br=tr.smetka_br
  40.  where extract(quarter from tr.datum)=2 and
  41.    extract(year from tr.datum)=god.godina
  42.     and s.klient_id=k.klient_id
  43. ) as prosek_iznos_trim_2,
  44. (select avg(tr.iznos)
  45. from transakcii as tr
  46.  join smetki as s on s.smetka_br=tr.smetka_br
  47.  where extract(quarter from tr.datum)=3 and
  48.    extract(year from tr.datum)=god.godina
  49.     and s.klient_id=k.klient_id
  50. ) as prosek_iznos_trim_3,
  51. (select avg(tr.iznos)
  52. from transakcii as tr
  53.  join smetki as s on s.smetka_br=tr.smetka_br
  54.  where extract(quarter from tr.datum)=4 and
  55.    extract(year from tr.datum)=god.godina
  56.     and s.klient_id=k.klient_id
  57. ) as prosek_iznos_trim_4
  58.  
  59. from klienti as k,
  60.  
  61. (select distinct extract(year from t.datum) godina
  62. from transakcii t) god
Advertisement
RAW Paste Data Copied
Advertisement