Q:

sql - SUM(CASE WHEN)

What's the difference between the two queries? 
1st query: 
SUM(CASE WHEN (condition_1) 
           OR (condition_2) 
           OR (condition_3) 
    THEN 1 ELSE 0 
    END)

2nd query: 
SUM(CASE WHEN (condition_1) THEN 1 ELSE 0 END +
    CASE WHEN (condition_2) THEN 1 ELSE 0 END +
    CASE WHEN (condition_3) THEN 1 ELSE 0 END)

A:

The two expression are not equivalent. The first expression adds one for every record that satisfies any of the 3 conditions. The second adds one for each record and condition that is met, so it can add up to 3 per records.
Unless the conditions are mutually exclusive, the results will be different.
Consider these conditions:
condition_1     id > 1
condition_2     id > 2
condition_3     id > 3

For this dataset:
id
---
1
2
4

The first expression would yield 2 (since 3 records out of 3 satisfy at least one of the conditions).
The second expression would yield 3 (since the third record satisfy two conditions, it will add 2 to the result).

