All Time Leads Stages

view name = 'all_time_leads_stages'

[NEW] Query

 SELECT to_char(date_trunc('month'::text, "timestamp")::date::timestamp with time zone, 'YYYY Mon'::text) AS month,
    (to_char(date_trunc('week'::text, "timestamp")::date::timestamp with time zone, 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, "timestamp")::date + '6 days'::interval, 'DD Mon'::text) AS week,
    date_trunc('day'::text, "timestamp")::date AS date,
    branch,
    contact_owner,
    assigned_pic,
    source,
    sremarks,
    medium,
    mremarks,
    count("timestamp") AS inbound,
    count(
        CASE
            WHEN leads_date::date = "timestamp"::date THEN leads_date
            ELSE NULL::timestamp without time zone
        END) AS leads,
    count(
        CASE
            WHEN mql_date::date = "timestamp"::date THEN mql_date
            ELSE NULL::timestamp without time zone
        END) AS mql,
    count(
        CASE
            WHEN "mqlPlus_date"::date = "timestamp"::date THEN "mqlPlus_date"
            ELSE NULL::timestamp without time zone
        END) AS mqlplus,
    count(
        CASE
            WHEN "tourPlus_date"::date = "timestamp"::date THEN "tourPlus_date"
            ELSE NULL::timestamp without time zone
        END) AS tourplus,
    count(
        CASE
            WHEN "trialPlus_date"::date = "timestamp"::date THEN "trialPlus_date"
            ELSE NULL::timestamp without time zone
        END) AS trialplus,
    count(
        CASE
            WHEN convert_date::date = "timestamp"::date THEN convert_date
            ELSE NULL::timestamp without time zone
        END) AS convert
   FROM leads
  GROUP BY (to_char(date_trunc('month'::text, "timestamp")::date::timestamp with time zone, 'YYYY Mon'::text)), ((to_char(date_trunc('week'::text, "timestamp")::date::timestamp with time zone, 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, "timestamp")::date + '6 days'::interval, 'DD Mon'::text)), (date_trunc('week'::text, "timestamp")::date), (date_trunc('day'::text, "timestamp")::date), branch, contact_owner, assigned_pic, source, sremarks, medium, mremarks
  ORDER BY (date_trunc('day'::text, "timestamp")::date);

Last updated