Skip to content

Instantly share code, notes, and snippets.

@whal-e3
Last active October 19, 2020 12:49
Show Gist options
  • Save whal-e3/60d3e2a2401a86272cb5fe1f39702bc0 to your computer and use it in GitHub Desktop.
Save whal-e3/60d3e2a2401a86272cb5fe1f39702bc0 to your computer and use it in GitHub Desktop.
PostgreSQL 13 cheat sheet
SELECT COUNT(DISTINCT(*)) FROM _somewhere_
WHERE _something_ <= 12 AND _something2_ = '_word_'
WHERE _something_ BETWEEN 8 AND 9
WHERE _something_ IN (0.99, 1.98, 1.99)
WHERE _something_ LIKE/ILIKE '_J%'
ORDER BY _something_ ASC, _something2_ DESC
LIMIT 5;
----------------------------------------------------------------------------------
MAX, MIN, AVG & ROUND, SUM
* GROUP BY - think blocks with same value as one block and operate aggregation function
SELECT col_1, col_2, aggregation_function(col_3) FROM table
GROUP BY aggregation_function(col_3)
ORDER BY ~ ~
~
HAVING
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment