🍕SQL

Basics

Keep in mind that the order of execution follows FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY.

-- Selecting columns to display in the result
SELECT Product, SUM(Amount) AS TotalSales

-- Specifying the table to retrieve data from
FROM Sales

-- Filtering data based on conditions
WHERE Region = 'East' AND YEAR(Date) = 2023

-- Grouping the result by the 'Product' column
GROUP BY Product

-- Filtering the grouped results based on aggregate conditions
HAVING SUM(Amount) > 10000

-- Ordering the final result by total sales in descending order
ORDER BY TotalSales DESC;

SQL Case

Create table

Insert data into a table

Delete table

Alter table

  • Add a new column

  • Rename a column

  • Change the data type of a column

  • Delete a column

Last updated