-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobservationSchedule.sql
More file actions
44 lines (44 loc) · 1.03 KB
/
observationSchedule.sql
File metadata and controls
44 lines (44 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
SELECT
g.id,
g.scheduledDate,
COUNT(g.caseid) cases,
o.observations,
SUM(g.obsCount) AS obsCount,
o.orderIds,
o.status,
o.taskids,
MAX(g.type) AS type,
MAX(g.caseid) AS caseid
FROM
(
SELECT
sch.animalId as id,
sch.date AS scheduledDate,
sch.caseid,
sch.type,
COUNT(sch.category) AS obsCount
FROM observationOrdersByDate sch
GROUP BY
sch.animalId,
sch.date,
sch.caseid,
sch.type
) g
LEFT JOIN (
SELECT
obs.animalId AS id,
obs.date AS scheduledDate,
GROUP_CONCAT(DISTINCT obs.category, ';') AS observations,
GROUP_CONCAT(obs.objectid, ';') AS orderIds,
GROUP_CONCAT(obs.obsStatus, ';') AS status,
GROUP_CONCAT(DISTINCT(obs.taskid), ';') AS taskids
FROM observationOrdersByDate obs
GROUP BY obs.animalId, obs.date
) o ON g.id = o.id AND g.scheduledDate = o.scheduledDate
GROUP BY
g.id,
g.scheduledDate,
o.observations,
o.orderIds,
o.status,
o.taskids