Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select A.month as month,
- Count(distinct A.lid) as cars_listed,
- count(distinct case when (A.listing_type = 'Individual' and A.insurance_package = 'Trevo-Shield') then A.lid end) as Individual_trevo_Sheild,
- count(distinct case when (A.listing_type = 'Individual' and A.insurance_package = 'Normal') then A.lid end) as Individual_no_insurance,
- count(distinct case when A.listing_type = 'Fleet' then A.lid end) as Fleet
- from
- (select distinct l.id as lid,l.status as status,
- cu.id as cuid,
- li.insurance_package_id as insurance_id,
- CASE WHEN cu.id IS NOT NULL THEN 'Fleet' ELSE 'Individual' END listing_type,
- CASE WHEN li.insurance_package_id=2 THEN 'Trevo-Shield' ELSE 'Normal' END insurance_package,
- extract('month' from l.created_at) as month
- from listings l
- LEFT JOIN company_users cu ON cu.user_id=l.user_id
- LEFT join listing_insurance li on li.listing_id = l.id
- WHERE l.status='approved' AND l.deleted_at IS NULL) A
- group by A.month
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement