| 14 | |
| 15 | To get total user reservations in minutes for certain period per machine: |
| 16 | |
| 17 | {{{ |
| 18 | SELECT machines.name resource_name, |
| 19 | sum((reservations.end_date + (reservations.endTime * 60))-(reservations.start_date + (reservations.startTime * 60)))/60 duration |
| 20 | FROM reservations |
| 21 | LEFT JOIN reservation_users ON reservation_users.resid = reservations.resid |
| 22 | LEFT JOIN machines ON reservations.machid = machines.machid |
| 23 | WHERE unix_timestamp('2000-01-01') <=(reservations.start_date + (reservations.startTime * 60)) AND |
| 24 | unix_timestamp('2016-03-31') >= (reservations.end_date + (reservations.endTime * 60)) |
| 25 | AND is_pending = 0 |
| 26 | GROUP BY resource_name |
| 27 | ORDER BY duration desc |
| 28 | }}} |
| 29 | |
| 30 | To get total resource reservations in minutes for certain period per machine. |
| 31 | This is slightly different than above because user can invite other user(s) to his reservation. |
| 32 | {{{ |
| 33 | SELECT machines.name resource_name, |
| 34 | sum((reservations.end_date + (reservations.endTime * 60))-(reservations.start_date + (reservations.startTime * 60)))/60 duration |
| 35 | FROM reservations |
| 36 | LEFT JOIN machines ON reservations.machid = machines.machid |
| 37 | WHERE unix_timestamp('2016-03-01') <=(reservations.start_date + (reservations.startTime * 60)) AND |
| 38 | unix_timestamp('2016-03-31') >= (reservations.end_date + (reservations.endTime * 60)) |
| 39 | AND is_pending = 0 |
| 40 | GROUP BY resource_name |
| 41 | ORDER BY resource_name; |
| 42 | }}} |
| 43 | |