TAC Appt - Appt
view name = 'tac_appt_appt'
[NEW] Query
WITH status_calculated AS (
SELECT date_trunc('day'::text, appt.appt_date)::date AS date,
to_char(date_trunc('month'::text, appt.appt_date), 'YYYY Mon'::text) AS month,
(to_char(date_trunc('week'::text, appt.appt_date), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, appt.appt_date) + '6 days'::interval, 'DD Mon'::text) AS week,
appt.branch,
appt.contact_owner,
appt.assigned_pic,
appt.created_by,
CASE
WHEN bool_or(appt."is_tour_show?") THEN true
WHEN bool_or(appt."is_trial_show?") THEN true
WHEN bool_or(appt."is_trial_show?") IS FALSE THEN false
WHEN bool_or(appt."is_tour_show?") IS FALSE THEN false
WHEN bool_or(appt."is_trial_show?") IS NULL THEN NULL::boolean
WHEN bool_or(appt."is_tour_show?") IS NULL THEN NULL::boolean
ELSE NULL::boolean
END AS status,
count(appt.appt_date) AS appt
FROM appt
WHERE appt.hide IS NULL OR appt.hide = false
GROUP BY (date_trunc('day'::text, appt.appt_date)::date), (to_char(date_trunc('month'::text, appt.appt_date), 'YYYY Mon'::text)), ((to_char(date_trunc('week'::text, appt.appt_date), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, appt.appt_date) + '6 days'::interval, 'DD Mon'::text)), appt.branch, appt.contact_owner, appt.assigned_pic, appt.created_by
)
SELECT date,
month,
week,
branch,
contact_owner,
assigned_pic,
created_by,
status,
sum(appt) AS appt
FROM status_calculated
GROUP BY date, month, week, branch, contact_owner, assigned_pic, created_by, status
ORDER BY date;
Last updated