| 2 | |
| 3 | |
| 4 | === Извештај за проверка колку студенти кои побарале специфична соба во првиот ден од рокот за вселување истата ја добиле како и информација за најмногу исполнет блок и број на зафатени соби |
| 5 | |
| 6 | SELECT |
| 7 | COUNT(DISTINCT str.student_id) AS br_studenti_zemale_soba_prv_den, |
| 8 | (SELECT |
| 9 | str.block_id |
| 10 | FROM StudentTookRoom str |
| 11 | GROUP BY str.block_id) AS blok_so_najvekje_zafateni_sobi, |
| 12 | b.num_available_rooms AS br_zafateni_sobi |
| 13 | FROM student s |
| 14 | JOIN roomrequest rr |
| 15 | ON s.u_id = rr.student_id |
| 16 | JOIN studenttookroom str |
| 17 | ON str.student_id = s.u_id |
| 18 | JOIN room r |
| 19 | ON r.room_number = str.room_num |
| 20 | JOIN block b |
| 21 | ON b.block_id = r.block_id |
| 22 | WHERE rr.status = 'Approved' |
| 23 | AND str.start_date = (SELECT MIN(start_date) FROM StudentTookRoom) |
| 24 | AND rr.room_number = str.room_num |
| 25 | group by b.num_available_rooms |
| 26 | |
| 27 | |
| 28 | === Извештај за бројка на доделени соба и блок на студенти кои побарале соодветна соба но истата не ја добиле |
| 29 | |
| 30 | SELECT |
| 31 | du.u_id AS student_id, |
| 32 | CONCAT(du.first_name, ' ', du.last_name) AS student_name, |
| 33 | rr.block_id AS requested_block, |
| 34 | rr.room_number AS requested_room, |
| 35 | str.block_id AS assigned_block, |
| 36 | str.room_num AS assigned_room, |
| 37 | COUNT(*) OVER (PARTITION BY rr.block_id, rr.room_number) AS mismatches_per_requested_room |
| 38 | FROM dorm_user du |
| 39 | JOIN roomrequest rr |
| 40 | ON du.u_id = rr.student_id |
| 41 | JOIN studenttookroom str |
| 42 | ON str.student_id = du.u_id |
| 43 | WHERE rr.block_id != str.block_id OR rr.room_number != str.room_num; |