I have created a Postgres table with the following schema,
create table exam_info
(
"venue" text not null, //value: "A", "B", "C", "D"
"time" int, //epoch time
"examData" jsonb not null
);
here is some example entries for examData column
{"id":"e73kf", "data":{"subject":"Science","year":"grade5"}}
{"id":"e3dsa", "data":{"subject":"English","year":"grade3"}}
I would like to find out for a specific subject(Science), how many exam has been hosted in each venue in a specific time range
subject venue count
"Science" A 10
"Science" B 5
"Science" C 7
"Science" D 11
When I tried to add a condition where exam = "Science" in the following query, an error column exam does not exist showed up.
SELECT
"examData" -> 'data' -> 'subject' as exam,
venue,
count(venue)
FROM
exam_info
WHERE
time >= ' ' AND time < ' '
GROUP BY
exam,venue
Thanks everyone!
count(*)will be slightly faster thancount(venue)