Leads View

view name = 'leads_view'

[NEW] Query

 SELECT uid,
    "timestamp",
    phone,
    email,
    name,
    gender,
    date_of_birth,
    age,
    age_group,
    branch,
    language,
    contact_owner,
    source,
    sremarks,
    content,
    medium,
    mremarks,
    assigned_pic,
    interest,
    leads_notes,
    leads_qualification,
    user_type,
    kyzn_account,
    sleekflow_id,
    leads_date,
    mql_date,
    "mqlPlus_date",
    "tourPlus_date",
    convert_date,
    loss_date,
    tour_date,
    "is_tour_show?",
    trial_date,
    "is_trial_show?",
    "is_inbound?",
    "is_leads?",
    "is_mql?",
    "is_mqlPlus?",
    "is_tourPlus?",
    "is_trialPlus?",
    "is_convert?",
    interest_remarks,
    submitted_email,
    assigned_email,
    "trialPlus_date",
    membership_name,
    package_name,
    start_membership,
    member_id,
    total_amount,
    payment_method,
    promotion,
    ref_program,
    ref_id,
    ref_name,
    ref_phone,
    identity_photo,
    status,
    convert_by,
    end_membership,
    signature,
    contract,
    offer_trial,
    reply_after_offer,
    last_appt_category,
    "conversationId",
    assigned_date,
        CASE
            WHEN tour_date IS NULL AND trial_date IS NOT NULL THEN trial_date
            WHEN trial_date IS NULL AND tour_date IS NOT NULL THEN tour_date
            WHEN tour_date IS NOT NULL AND trial_date IS NOT NULL THEN GREATEST(tour_date, trial_date)
            ELSE NULL::timestamp without time zone
        END AS appt_date,
    (to_char(date_trunc('week'::text, "timestamp"), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, "timestamp") + '6 days'::interval, 'DD Mon'::text) AS week_inbound,
    (to_char(date_trunc('week'::text, mql_date), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, mql_date) + '6 days'::interval, 'DD Mon'::text) AS week_mql,
    (to_char(date_trunc('week'::text, "mqlPlus_date"), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, "mqlPlus_date") + '6 days'::interval, 'DD Mon'::text) AS week_mqlplus,
    (to_char(date_trunc('week'::text,
        CASE
            WHEN tour_date IS NULL AND trial_date IS NOT NULL THEN trial_date
            WHEN trial_date IS NULL AND tour_date IS NOT NULL THEN tour_date
            WHEN tour_date IS NOT NULL AND trial_date IS NOT NULL THEN GREATEST(tour_date, trial_date)
            ELSE NULL::timestamp without time zone
        END), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text,
        CASE
            WHEN tour_date IS NULL AND trial_date IS NOT NULL THEN trial_date
            WHEN trial_date IS NULL AND tour_date IS NOT NULL THEN tour_date
            WHEN tour_date IS NOT NULL AND trial_date IS NOT NULL THEN GREATEST(tour_date, trial_date)
            ELSE NULL::timestamp without time zone
        END) + '6 days'::interval, 'DD Mon'::text) AS week_appt_date,
    (to_char(date_trunc('week'::text, convert_date), 'DD Mon'::text) || ' - '::text) || to_char(date_trunc('week'::text, convert_date) + '6 days'::interval, 'DD Mon'::text) AS week_convert,
    last_created_by,
    hide
   FROM leads
  WHERE hide IS NULL OR hide = false;

Last updated