SELECT * FROM test;
It is based on this form:
CASE WHEN condition THEN result
It is very convenient in aggregation functions, just think table foo below:
id is table’s primary key, sex is 0 or 1, it stands for male and female.
Now, how can we lookup how many males and females at the same time ?
SELECT sum(CASE WHEN sex=0 THEN 1 ELSE 0 END) AS total_male,