fix union queries for dashboard stats

This commit is contained in:
msquare 2017-12-14 19:39:47 +01:00
parent 35be25a786
commit 20f4d44cbf
2 changed files with 5 additions and 3 deletions

View File

@ -38,6 +38,7 @@ function Shifts_free($start, $end)
WHERE (`end` > ? AND `start` < ?)
AND (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`)
> (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
AND `Shifts`.`PSID` IS NULL
UNION
@ -46,6 +47,7 @@ function Shifts_free($start, $end)
WHERE (`end` > ? AND `start` < ?)
AND (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`)
> (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0)
AND NOT `Shifts`.`PSID` IS NULL
) as `tmp`
ORDER BY `tmp`.`start`
", [

View File

@ -35,7 +35,7 @@ function stats_hours_to_work()
WHERE `end` >= ?
AND `Shifts`.`PSID` IS NULL
UNION
UNION ALL
SELECT
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`)
@ -71,7 +71,7 @@ function stats_angels_needed_three_hours()
WHERE `end` > ? AND `start` < ?
AND `Shifts`.`PSID` IS NULL
UNION
UNION ALL
SELECT
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`)
@ -109,7 +109,7 @@ function stats_angels_needed_for_nightshifts()
WHERE `end` > ? AND `start` < ?
AND `Shifts`.`PSID` IS NULL
UNION
UNION ALL
SELECT
(SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID`)