Conditional logic & CASE
Exercise · SQL & Querying

Predict, then run it

Predict the output

sales(region, amount) = (N,100),(S,200),(N,50). Pivot the totals into one row:

SELECT SUM(CASE WHEN region='N' THEN amount END) AS north, SUM(CASE WHEN region='S' THEN amount END) AS south FROM sales;

Predict the exact output.