30 | | == 2. |
| 30 | == 2. Извештај за првите три прашања со најмногу одговори од студенти и професори посебно, потоа од тие прашања ја пресметуваме вкупната сума на реакции на одговорите(заедно од професори и студенти) и ги филтритаме само оние кои имаат просечен или надпросечен број на реакции |
| 31 | {{{ |
| 32 | create view broj_reakcii_na_izbrani_odgovori as ( |
| 33 | select sum(q4.br_reakcii) as br_reakcii_total, q4.o_id, q4.pra_id from ( |
| 34 | select count(dr.reakcija) as br_reakcii, o.o_id , o.pra_id from ( |
| 35 | select * from ( |
| 36 | select p.pra_id as prasanje from prasanja p |
| 37 | join odgovori o on o.pra_id =p .pra_id |
| 38 | where o.s_id is not null |
| 39 | group by p.pra_id |
| 40 | order by count(o.o_id) desc |
| 41 | limit 3 ) as q1 |
| 42 | union |
| 43 | select q2.prasanje from ( |
| 44 | select p.pra_id as prasanje from prasanja p |
| 45 | join odgovori o on o.pra_id =p .pra_id |
| 46 | where o.p_id is not null |
| 47 | group by p.pra_id |
| 48 | order by count(o.o_id) desc |
| 49 | limit 3 ) as q2 |
| 50 | ) as q3 |
| 51 | join prasanja p2 on q3.prasanje = p2.pra_id |
| 52 | join odgovori o on o.pra_id =p2.pra_id |
| 53 | join dava_reakcija dr on o.o_id = dr.o_id |
| 54 | group by o.o_id, o.pra_id |
| 55 | union |
| 56 | select count(rn.reakcija) as br_reakcii, o.o_id , o.pra_id from ( |
| 57 | select * from ( |
| 58 | select p.pra_id as prasanje from prasanja p |
| 59 | join odgovori o on o.pra_id =p .pra_id |
| 60 | where o.s_id is not null |
| 61 | group by p.pra_id |
| 62 | order by count(o.o_id) desc |
| 63 | limit 3 ) as q1 |
| 64 | union |
| 65 | select q2.prasanje from ( |
| 66 | select p.pra_id as prasanje from prasanja p |
| 67 | join odgovori o on o.pra_id =p .pra_id |
| 68 | where o.p_id is not null |
| 69 | group by p.pra_id |
| 70 | order by count(o.o_id) desc |
| 71 | limit 3 ) as q2 |
| 72 | ) as q3 |
| 73 | join prasanja p2 on q3.prasanje = p2.pra_id |
| 74 | join odgovori o on o.pra_id =p2.pra_id |
| 75 | join reagira_na rn on o.o_id = rn.o_id |
| 76 | group by o.o_id, o.pra_id |
| 77 | ) as q4 |
| 78 | group by q4.o_id , q4.pra_id |
| 79 | ); |
| 80 | |
| 81 | |
| 82 | create view broj_reakcii_na_odgovor as ( |
| 83 | select sum(q4.br_reakcii) as br_reakcii_total, q4.o_id, q4.pra_id from ( |
| 84 | select count(dr.reakcija) as br_reakcii, o.o_id , o.pra_id from ( |
| 85 | select q1.prasanje from ( |
| 86 | select p.pra_id as prasanje from prasanja p |
| 87 | join odgovori o on o.pra_id =p .pra_id |
| 88 | group by p.pra_id |
| 89 | ) as q1 |
| 90 | union |
| 91 | select q2.prasanje from ( |
| 92 | select p.pra_id as prasanje from prasanja p |
| 93 | join odgovori o on o.pra_id =p .pra_id |
| 94 | group by p.pra_id |
| 95 | ) as q2 |
| 96 | ) as q3 |
| 97 | join prasanja p2 on q3.prasanje = p2.pra_id |
| 98 | join odgovori o on o.pra_id =p2.pra_id |
| 99 | join dava_reakcija dr on o.o_id = dr.o_id |
| 100 | group by o.o_id, o.pra_id |
| 101 | union |
| 102 | select count(rn.reakcija) as br_reakcii, o.o_id , o.pra_id from ( |
| 103 | select q1.prasanje from ( |
| 104 | select p.pra_id as prasanje from prasanja p |
| 105 | join odgovori o on o.pra_id =p .pra_id |
| 106 | group by p.pra_id |
| 107 | ) as q1 |
| 108 | union |
| 109 | select q2.prasanje from ( |
| 110 | select p.pra_id as prasanje from prasanja p |
| 111 | join odgovori o on o.pra_id =p .pra_id |
| 112 | group by p.pra_id |
| 113 | ) as q2 |
| 114 | ) as q3 |
| 115 | join prasanja p2 on q3.prasanje = p2.pra_id |
| 116 | join odgovori o on o.pra_id =p2.pra_id |
| 117 | join reagira_na rn on o.o_id = rn.o_id |
| 118 | group by o.o_id, o.pra_id |
| 119 | ) as q4 |
| 120 | group by q4.o_id , q4.pra_id |
| 121 | ); |
| 122 | |
| 123 | select brnio.br_reakcii_total, p.* from broj_reakcii_na_izbrani_odgovori brnio |
| 124 | join prasanja p on brnio.pra_id = p.pra_id |
| 125 | where brnio.br_reakcii_total >= (select avg(brno.br_reakcii_total) from broj_reakcii_na_odgovor brno) |
| 126 | }}} |