33 | | select count(dr.reakcija) as br_reakcii, o.o_id , o.pra_id from ( |
| 33 | select ( (select count(*) from dava_reakcija as dr where dr.o_id = o.o_id and dr.reakcija = true) - |
| 34 | (select count(*) from dava_reakcija as dr where dr.o_id = o.o_id and dr.reakcija = false) ) as br_reakcii, o.o_id , o.pra_id |
| 35 | from (select q1.prasanje |
| 36 | from (select p.pra_id as prasanje |
| 37 | from prasanja p |
| 38 | join odgovori o on o.pra_id = p.pra_id |
| 39 | group by p.pra_id) as q1 |
| 40 | union |
| 41 | select q2.prasanje |
| 42 | from (select p.pra_id as prasanje |
| 43 | from prasanja p |
| 44 | join odgovori o on o.pra_id = p.pra_id |
| 45 | group by p.pra_id) as q2) as q3 |
| 46 | join prasanja p2 on q3.prasanje = p2.pra_id |
| 47 | join odgovori o on o.pra_id =p2.pra_id |
| 48 | join dava_reakcija dr on o.o_id = dr.o_id |
| 49 | group by o.o_id, o.pra_id |
| 50 | union |
| 51 | select ( (select count(*) from reagira_na as rn where rn.o_id = o.o_id and rn.reakcija = true) - |
| 52 | (select count(*) from reagira_na as rn where rn.o_id = o.o_id and rn.reakcija = false) ) as br_reakcii, o.o_id , o.pra_id from ( |
52 | | join prasanja p2 on q3.prasanje = p2.pra_id |
| 71 | join prasanja p2 on q3.prasanje = p2.pra_id |
| 72 | join odgovori o on o.pra_id =p2.pra_id |
| 73 | join reagira_na rn on o.o_id = rn.o_id |
| 74 | group by o.o_id, o.pra_id |
| 75 | ) as q4 |
| 76 | group by q4.o_id , q4.pra_id); |
| 77 | |
| 78 | create view broj_reakcii_na_odgovor as ( |
| 79 | select sum(q4.br_reakcii) as br_reakcii_total, q4.o_id, q4.pra_id from ( |
| 80 | select ( (select count(*) from dava_reakcija as dr where dr.o_id = o.o_id and dr.reakcija = true) - |
| 81 | (select count(*) from dava_reakcija as dr where dr.o_id = o.o_id and dr.reakcija = false) ) as br_reakcii, o.o_id , o.pra_id from ( |
| 82 | select q1.prasanje from ( |
| 83 | select p.pra_id as prasanje from prasanja p |
| 84 | join odgovori o on o.pra_id =p .pra_id |
| 85 | group by p.pra_id |
| 86 | ) as q1 |
| 87 | union |
| 88 | select q2.prasanje from ( |
| 89 | select p.pra_id as prasanje from prasanja p |
| 90 | join odgovori o on o.pra_id =p .pra_id |
| 91 | group by p.pra_id |
| 92 | ) as q2 |
| 93 | ) as q3 |
| 94 | join prasanja p2 on q3.prasanje = p2.pra_id |
57 | | select count(rn.reakcija) as br_reakcii, o.o_id , o.pra_id from ( |
58 | | select * from ( |
59 | | select p.pra_id as prasanje from prasanja p |
60 | | join odgovori o on o.pra_id =p .pra_id |
61 | | where o.s_id is not null |
62 | | group by p.pra_id |
63 | | order by count(o.o_id) desc |
64 | | limit 3 |
| 99 | select ( (select count(*) from reagira_na as rn where rn.o_id = o.o_id and rn.reakcija = true) - |
| 100 | (select count(*) from reagira_na as rn where rn.o_id = o.o_id and rn.reakcija = false) ) as br_reakcii, o.o_id , o.pra_id from ( |
| 101 | select q1.prasanje from ( |
| 102 | select p.pra_id as prasanje from prasanja p |
| 103 | join odgovori o on o.pra_id =p .pra_id |
| 104 | group by p.pra_id |
85 | | create view broj_reakcii_na_odgovor as ( |
86 | | select sum(q4.br_reakcii) as br_reakcii_total, q4.o_id, q4.pra_id from ( |
87 | | select count(dr.reakcija) as br_reakcii, o.o_id , o.pra_id from ( |
88 | | select q1.prasanje from ( |
89 | | select p.pra_id as prasanje from prasanja p |
90 | | join odgovori o on o.pra_id =p .pra_id |
91 | | group by p.pra_id |
92 | | ) as q1 |
93 | | union |
94 | | select q2.prasanje from ( |
95 | | select p.pra_id as prasanje from prasanja p |
96 | | join odgovori o on o.pra_id =p .pra_id |
97 | | group by p.pra_id |
98 | | ) as q2 |
99 | | ) as q3 |
100 | | join prasanja p2 on q3.prasanje = p2.pra_id |
101 | | join odgovori o on o.pra_id =p2.pra_id |
102 | | join dava_reakcija dr on o.o_id = dr.o_id |
103 | | group by o.o_id, o.pra_id |
104 | | union |
105 | | select count(rn.reakcija) as br_reakcii, o.o_id , o.pra_id from ( |
106 | | select q1.prasanje from ( |
107 | | select p.pra_id as prasanje from prasanja p |
108 | | join odgovori o on o.pra_id =p .pra_id |
109 | | group by p.pra_id |
110 | | ) as q1 |
111 | | union |
112 | | select q2.prasanje from ( |
113 | | select p.pra_id as prasanje from prasanja p |
114 | | join odgovori o on o.pra_id =p .pra_id |
115 | | group by p.pra_id |
116 | | ) as q2 |
117 | | ) as q3 |
118 | | join prasanja p2 on q3.prasanje = p2.pra_id |
119 | | join odgovori o on o.pra_id =p2.pra_id |
120 | | join reagira_na rn on o.o_id = rn.o_id |
121 | | group by o.o_id, o.pra_id |
122 | | ) as q4 |
123 | | group by q4.o_id , q4.pra_id |
124 | | ); |
125 | | |
126 | | select brnio.br_reakcii_total, p.* from broj_reakcii_na_izbrani_odgovori brnio |
127 | | join prasanja p on brnio.pra_id = p.pra_id |
128 | | where brnio.br_reakcii_total >= (select avg(brno.br_reakcii_total) from broj_reakcii_na_odgovor brno) |
| 122 | select pras.*, q2.sum from (select distinct q1.pra_id, sum(q1.br_reakcii_total) |
| 123 | from (select brnio.br_reakcii_total, p.* |
| 124 | from broj_reakcii_na_izbrani_odgovori brnio |
| 125 | join prasanja p on brnio.pra_id = p.pra_id |
| 126 | join odgovori o on brnio.o_id = o.o_id |
| 127 | where brnio.br_reakcii_total >= |
| 128 | (select avg(brno.br_reakcii_total) from broj_reakcii_na_odgovor brno)) as q1 |
| 129 | group by q1.pra_id) as q2 |
| 130 | join prasanja as pras on pras.pra_id = q2.pra_id; |