How to Use CASE WHEN With SUM() in SQL | LearnSQL.com

PHOTO EMBED

Wed Mar 16 2022 07:51:16 GMT+0000 (Coordinated Universal Time)

Saved by @Bambibo9799

SELECT 
  ship_country,
  SUM(CASE
    WHEN status = 'shipped' OR status = 'delivered' THEN 1
    ELSE 0
  END) AS order_shipped
FROM orders
GROUP BY ship_country;
content_copyCOPY

https://learnsql.com/blog/case-when-with-sum/