Skip to content

Instantly share code, notes, and snippets.

@AABur
Last active January 27, 2022 11:23
Show Gist options
  • Select an option

  • Save AABur/2c246672ceb6ea148c4bb0fe11a214cc to your computer and use it in GitHub Desktop.

Select an option

Save AABur/2c246672ceb6ea148c4bb0fe11a214cc to your computer and use it in GitHub Desktop.
SQL-order

Порядок выполнения SQL-операций

SELECT genre.name, COUNT(*) 
FROM genre 
JOIN movie ON movie.genre_id = genre.id 
WHERE movie.rating > 3 
GROUP BY genre.id 
ORDER BY COUNT(*) DESC
HAVING COUNT(*) > 3
  1. FROM (выбор таблицы)
  2. JOIN (комбинация с подходящими по условию данными из других таблиц)
  3. WHERE (фильтрация строк)
  4. GROUP BY (агрегирование данных)
  5. HAVING (фильтрация агрегированных данных)
  6. SELECT (возврат результирующего датасета)
  7. ORDER BY (сортировка).

https://techrocks.ru/2021/03/05/order-of-sql-operations/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment