0
select room_id,count (distinct(patient_id)) as patient_id 
from patient_flow where time='CURRENT_TIME'; 

I need the number of patients ids with corresponding room_ids at the current time.

 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

I wrote the query above, but it does not execute.

olevegard
  • 5,294
  • 1
  • 25
  • 29
Pari Venthan
  • 59
  • 1
  • 1
  • 8

2 Answers2

0

You missed the GROUP BY when using with aggregate function COUNT(). The below query will work:

SELECT room_id, COUNT (DISTINCT(patient_id)) AS patient_id 
FROM patient_flow 
WHERE time = CURRENT_DATE
GROUP BY room_id;
Arulkumar
  • 12,966
  • 14
  • 47
  • 68
0
select current_time, room_id, count (distinct(patient_id)) as patient_id from patient_flow  group by room_id;

I got result while executing above query..

Pari Venthan
  • 59
  • 1
  • 1
  • 8