SQL 4:
1. CASE WHEN condition 1 THEN result 1
WHEN condition 2 THEN result 2
ELSE result 3 END AS column_name
2. Using CASE with aggregate functions:
Write a query containing the CASE statement first, then COUNT, SUM, AVG......
3. Using CASE inside of aggregate functions (Pivoting)
COUNT (CASE WHEN)
4. DISTINCT: used for viewing unique values.
include multiple columns in a SELECT DISTINCT clause, the results will contain all of the unique pairs of those columns.
注:include DISTINCT once in the SELECT clause
particularly helpful when exploring a new data set.
using DISTINCT in aggregations-
COUNT DISTINCT
COUNT (DISTINCT CASE WHEN.....)
using DISTINCT, particularly in aggregations, can slow your queries down quite a bit.
5. JOIN: working with data from multiple tables
SELECT *
FROM a table JOIN another table ON....
重命名不用加AS