Calculations

1. Substitute null values in col1 with 0.
SELECT COALESCE(col1, 0)
2. Return 1 if the difference between col1 and col2 is more than 10 else 0.
CASE
  WHEN col1 - col2 > 10 THEN 1
  ELSE 0
END
3. Create a column that stores the difference col1 and col2.
SELECT col_1 - Col_2 AS diff
4. Count the number of rows that has the difference between col1 and col2 more than 10.
SELECT COUNT(CASE WHEN col1 - col2 > 10 THEN 1 ELSE NULL END) 
Last updated on 22 Aug 2024