0
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

我写了上面的查询,但它没有执行。

4

2 回答 2

0
select current_time, room_id, count (distinct(patient_id)) as patient_id from patient_flow  group by room_id;

我在执行上述查询时得到了结果..

于 2015-08-24T10:19:08.690 回答
0

您错过了GROUP BY使用 with aggregate function 时的情况COUNT()。以下查询将起作用:

SELECT room_id, COUNT (DISTINCT(patient_id)) AS patient_id 
FROM patient_flow 
WHERE time = CURRENT_DATE
GROUP BY room_id;
于 2015-08-24T08:36:35.900 回答