Advertisement
ahmedrahil786

TTT - (INFRA) - Cars Information for Dashboard

Dec 8th, 2019
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. select A.month as month,
  2. Count(distinct A.lid) as cars_listed,
  3. count(distinct case when (A.listing_type = 'Individual' and A.insurance_package = 'Trevo-Shield') then A.lid end) as Individual_trevo_Sheild,
  4. count(distinct case when (A.listing_type = 'Individual' and A.insurance_package = 'Normal') then A.lid end) as Individual_no_insurance,
  5. count(distinct case when A.listing_type = 'Fleet' then A.lid end) as Fleet
  6. from
  7. (select distinct l.id as lid,l.status as status,
  8. cu.id as cuid,
  9. li.insurance_package_id as insurance_id,
  10. CASE WHEN cu.id IS NOT NULL THEN 'Fleet' ELSE 'Individual' END listing_type,
  11. CASE WHEN li.insurance_package_id=2 THEN 'Trevo-Shield' ELSE 'Normal' END insurance_package,
  12. extract('month' from l.created_at) as month
  13. from listings l
  14. LEFT JOIN company_users cu ON cu.user_id=l.user_id
  15. LEFT join listing_insurance li on li.listing_id = l.id
  16. WHERE l.status='approved' AND l.deleted_at IS NULL) A
  17. group by A.month
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement