KYZN Docs
Home
  • Welcome
  • Intro
    • What is KYZN?
    • Age Group
  • KYZN Funnel
    • Glossary
      • General
      • Tracking Framework
    • Report
      • TAC Funnel
      • TCC Funnel
      • TAC Sleekflow
  • KYZN CRM
    • Glossary
      • My Leads
        • Add Leads
        • Add Family Leads
        • Add Appointment
        • Add Membership
        • Edit Branch
        • Edit PIC
        • Edit & Delete Leads
        • Search Leads
        • Reschedule Appointment
        • Clear Abnormal Stage
      • Approach
      • Pool
      • My Appt
        • Edit & Delete Appointment
        • Trial Form
      • My Convert
      • User Manager
      • UTM Generator
      • Assign PIC
      • Set Target
      • Schedule List
    • Event Bulk Data
  • Digital System
    • ETL Process
      • Query Checking
        • Cek Funnel Stage
        • Insert from temp_leads
        • Insert from sleekflow
        • Check Duplicate
        • Update Source Ads
        • Conversion Duration Analysist
        • Cek branch tidak match
        • Select Potential Contact
      • Query View
        • TAC Combined
        • TAC
        • TAC Appt
        • TAC Appt - Appt
        • TAC Appt - MQL
        • TAC Appt - MQLplus
        • TAC Appt - Tourplus
        • TAC Appt - Trialplus
        • TAC Convert
        • TAC Inbound
        • TAC Leads
        • TAC MQL
        • TAC MQLplus
        • TAC Tourplus
        • TAC Trialplus
        • Target View
        • Leads View
        • Appt View
        • Actual vs Target
        • All Time Leads Stages
        • All Time Appt Date
        • Budget Control
      • Database Management
        • pgAdmin
        • Looker Studio
  • Changelog
    • 2025-03
Powered by GitBook
On this page
  1. Digital System
  2. ETL Process
  3. Query View

TAC Appt

view name = 'tac_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
                    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
        ), mql_calculated AS (
         SELECT date_trunc('day'::text, appt.mql_date)::date AS date,
            to_char(date_trunc('month'::text, appt.mql_date), 'YYYY Mon'::text) AS month,
            (to_char(date_trunc('week'::text, appt.mql_date), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, appt.mql_date) + '6 days'::interval, 'DD Mon'::text) AS week,
            appt.branch,
            appt.contact_owner,
            appt.assigned_pic,
            appt.created_by,
            count(appt.mql_date) AS mql
           FROM appt
          WHERE appt.hide IS NULL OR appt.hide = false
          GROUP BY (date_trunc('day'::text, appt.mql_date)::date), (to_char(date_trunc('month'::text, appt.mql_date), 'YYYY Mon'::text)), ((to_char(date_trunc('week'::text, appt.mql_date), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, appt.mql_date) + '6 days'::interval, 'DD Mon'::text)), appt.branch, appt.contact_owner, appt.assigned_pic, appt.created_by
        )
 SELECT COALESCE(sc.date, mc.date) AS date,
    COALESCE(sc.month, mc.month) AS month,
    COALESCE(sc.week, mc.week) AS week,
    COALESCE(sc.branch, mc.branch) AS branch,
    COALESCE(sc.contact_owner, mc.contact_owner) AS contact_owner,
    COALESCE(sc.assigned_pic, mc.assigned_pic) AS assigned_pic,
    COALESCE(sc.created_by, mc.created_by) AS created_by,
    sc.status,
    COALESCE(sc.appt, 0::bigint) AS total_appt,
    COALESCE(mc.mql, 0::bigint) AS total_mql
   FROM status_calculated sc
     FULL JOIN mql_calculated mc ON sc.date = mc.date AND sc.branch = mc.branch AND sc.contact_owner = mc.contact_owner AND sc.assigned_pic = mc.assigned_pic AND sc.created_by = mc.created_by
  ORDER BY (COALESCE(sc.date, mc.date)), (COALESCE(sc.branch, mc.branch));

PreviousTACNextTAC Appt - Appt

Last updated 5 months ago