Useful Notes and Links

Reynier Cruz-Torres, PhD

GROUP BY

SELECT category_col, AGG(data_col) FROM table WHERE category_col != 'A' GROUP BY category_col;
SELECT company, SUM(sales) FROM table WHERE GROUP BY company ORDER BY SUM(sales);
SELECT DATE(payment_date),SUM(payment) GROUP BY DATE(payment_date);

HAVING

SELECT company, SUM(sales) FROM table WHERE company != 'Google' GROUP BY company HAVING SUM(sales) > 1000;

AS

Create an alias for a column or result

SELECT column AS new_name FROM table;

The AS operator gets executed at the very end of a query. We cannot use the alias inside a WHERE operator.