Advertisement
elena1234

pivoting with count and case in MySQL

Feb 20th, 2023
1,094
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.21 KB | None | 0 0
  1. SELECT store_id,
  2.        COUNT(CASE WHEN active = 1 THEN customer_id  ELSE NULL END) as active,
  3.        COUNT(CASE WHEN active = 0 THEN customer_id ELSE NULL  END) as inactive
  4. FROM customer
  5. GROUP BY store_id;
  6.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement