select room_id,count (distinct(patient_id)) as patient_id
from patient_flow where time='CURRENT_TIME';
我需要当前时间相应room_ids的患者ID数量。
id | patient_id | room_id | time
----+-------------+---------+---------------------
1 | 00035-67351 | 1 | 2015-06-09 10:11:20
1 | 00035-67351 | 2 | 2015-06-09 10:31:20
1 | 00035-67351 | 1 | 2015-06-09 10:12:20
1 | 00035-67351 | 1 | 2015-06-09 10:12:40
1 | 00035-67351 | 1 | 2015-06-09 10:15:40
1 | 00035-67351 | 1 | 2015-06-09 10:30:40
1 | 00035-67351 | 2 | 2015-06-09 10:32:40
1 | 00035-67351 | 2 | 2015-06-09 10:36:40
1 | 00035-67351 | 2 | 2015-06-09 10:38:40
1 | 00035-67351 | 2 | 2015-06-09 10:50:40
我写了上面的查询,但它没有执行。
答案 0 :(得分:0)
使用汇总功能GROUP BY
时,您错过了COUNT()
。以下查询将起作用:
SELECT room_id, COUNT (DISTINCT(patient_id)) AS patient_id
FROM patient_flow
WHERE time = CURRENT_DATE
GROUP BY room_id;
答案 1 :(得分:0)
select current_time, room_id, count (distinct(patient_id)) as patient_id from patient_flow group by room_id;
我在执行上述查询时得到了结果..