Reputation: 1
I am not an expert in writing postgresql queries, need some help in here.
I am using a tool to make a dashboard retool.com. I have 2 tables users and interviewers. A user is an interviewer as well as interviewee. When users id is saved as interviewer_id in interviews table he is considered as interviewer, in the same way when the user id is saved as interviewee_id he is considered as interviewee. start_time column in interviews saves the interview start time. interviews_slots column in users table has the interviewer slots in json form. see the sample data here.
`
{
"monday": [
{
"start-time": "09:00",
"end-time": "17:30"
}
],
"tuesday": [
{
"start-time": "09:00",
"end-time": "17:30"
}
],
"wednesday": [
{
"start-time": "09:00",
"end-time": "17:30"
}
],
"thursday": [
{
"start-time": "09:00",
"end-time": "17:30"
}
],
"friday": [
{
"start-time": "09:00",
"end-time": "17:30"
}
]
}
This is my sql statement.
SELECT users_tbl.id,
users_tbl.name,
(select name from users where id = interview_tbl.interviewee_id) as interviewee,
interview_tbl,start_time,
interview_tbl.duration,
interview_slots,
concat(users_tbl.interview_slots->'monday'->0->'start-time',' - ', users_tbl.interview_slots->'monday'->0->'end-time')
as Monday,
concat(users_tbl.interview_slots->'tuesday'->0->'start-time',' - ', users_tbl.interview_slots->'tuesday'->0->'end-time')
as Tuesday,
concat(users_tbl.interview_slots->'wednesday'->0->'start-time',' - ', users_tbl.interview_slots->'wednesday'->0->'end-time')
as Wednesday,
concat(users_tbl.interview_slots->'thursday'->0->'start-time',' - ', users_tbl.interview_slots->'thursday'->0->'end-time')
as Thursday,
concat(users_tbl.interview_slots->'friday'->0->'start-time',' - ', users_tbl.interview_slots->'friday'->0->'end-time')
as Friday,
concat(users_tbl.interview_slots->'saturday'->0->'start-time',' - ', users_tbl.interview_slots->'saturday'->0->'end-time')
as Saturday,
concat(users_tbl.interview_slots->'sunday'->0->'start-time',' - ',users_tbl.interview_slots->'sunday'->0->'end-time')
as Sunday
FROM users as users_tbl
JOIN interviews interview_tbl
ON users_tbl.id=interview_tbl.interviewer_id
AND interview_tbl.created_at >= CURRENT_DATE;
I want to query out the data based on the interview start_time suppose a interview is set for Tuesday i.e 20th Dec at 10:00 am for 1 hour, i need to display a interviewer is available slots for Tuesday like
consider the sample data is used to display
Interviewer | Tuesday occupied slots | Available Slots |
---|---|---|
Batman | 20th Dec at 10:00 am | 9:00 - 10:00, |
11:00 - 17:30. |
Again in need to display similar data for the whole current week. Thanks in advance.
Upvotes: 0
Views: 92