Advertisement
Sofe1204

Untitled

Mar 29th, 2022
687
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select g.g_naziv grad, god.godina,
  2. (
  3. select count(distinct tr.trans_br||'-'||tr.smetka_br)
  4.   from transakcii tr
  5.   join smetki s on s.smetka_br=tr.smetka_br
  6.   join klienti k on k.klient_id=s.klient_id
  7.   where extract(quarter from tr.datum)=1
  8.   and extract(year from tr.datum) = god.godina
  9.   and k.grad_id=g.grad_id
  10. ) br_trans_trim_1,
  11. (
  12. select count(distinct tr.trans_br||'-'||tr.smetka_br)
  13.   from transakcii tr
  14.   join smetki s on s.smetka_br=tr.smetka_br
  15.   join klienti k on k.klient_id=s.klient_id
  16.   where extract(quarter from tr.datum)=2
  17.   and extract(year from tr.datum) = god.godina
  18.   and k.grad_id=g.grad_id
  19. ) br_trans_trim_2,
  20. (
  21. select count(distinct tr.trans_br||'-'||tr.smetka_br)
  22.   from transakcii tr
  23.   join smetki s on s.smetka_br=tr.smetka_br
  24.   join klienti k on k.klient_id=s.klient_id
  25.   where extract(quarter from tr.datum)=3
  26.   and extract(year from tr.datum) = god.godina
  27.   and k.grad_id=g.grad_id
  28. ) br_trans_trim_3,
  29. (
  30. select count(distinct tr.trans_br||'-'||tr.smetka_br)
  31.   from transakcii tr
  32.   join smetki s on s.smetka_br=tr.smetka_br
  33.   join klienti k on k.klient_id=s.klient_id
  34.   where extract(quarter from tr.datum)=4
  35.   and extract(year from tr.datum) = god.godina
  36.   and k.grad_id=g.grad_id
  37. ) br_trans_trim_4,
  38. (
  39. select sum(tr.iznos)
  40.   from transakcii tr
  41.   join smetki s on s.smetka_br=tr.smetka_br
  42.   join klienti k on k.klient_id=s.klient_id
  43.   where extract(quarter from tr.datum)=1
  44.   and extract(year from tr.datum) = god.godina
  45.   and k.grad_id=g.grad_id
  46. ) suma_iznos_trim_1,
  47. (
  48. select sum(tr.iznos)
  49.   from transakcii tr
  50.   join smetki s on s.smetka_br=tr.smetka_br
  51.   join klienti k on k.klient_id=s.klient_id
  52.   where extract(quarter from tr.datum)=2
  53.   and extract(year from tr.datum) = god.godina
  54.   and k.grad_id=g.grad_id
  55. ) suma_iznos_trim_2,
  56. (
  57. select sum(tr.iznos)
  58.   from transakcii tr
  59.   join smetki s on s.smetka_br=tr.smetka_br
  60.   join klienti k on k.klient_id=s.klient_id
  61.   where extract(quarter from tr.datum)=3
  62.   and extract(year from tr.datum) = god.godina
  63.   and k.grad_id=g.grad_id
  64. ) suma_iznos_trim_3,
  65. (
  66. select sum(tr.iznos)
  67.   from transakcii tr
  68.   join smetki s on s.smetka_br=tr.smetka_br
  69.   join klienti k on k.klient_id=s.klient_id
  70.   where extract(quarter from tr.datum)=4
  71.   and extract(year from tr.datum) = god.godina
  72.   and k.grad_id=g.grad_id
  73. ) suma_iznos_trim_4
  74. from gradovi g,
  75. (select distinct extract(year from t.datum) godina from transakcii t) god
Advertisement
RAW Paste Data Copied
Advertisement