Update for 28-02-22 16:45

This commit is contained in:
Tyler Perkins 2022-02-28 16:45:01 -05:00
parent f90e79bc90
commit ac2b63ba57

View File

@ -34,7 +34,68 @@ will return all bands with the string 'light' in their name.
=== DISTINCT === === DISTINCT ===
`DISTINCT` filters results by only returning unique values in a column `DISTINCT` filters results by only returning unique values of a column.
Therefore, we can only be used to return a single column.
{{{
SELECT DISTINCT nationality FROM users;
}}}
== Presentation ==
=== Order by ===
`ORDER BY` allows us to descide how the query will be shown. For example,
{{{
SELECT Firstname, Lastname
FROM users
ORDER BY Lastname [SORT];
}}}
where `[SORT]` is
* DESC
* descending order
* ASC
* ascending order
=== CASE ===
Case is a statement block where we can choose exactly what text is returned
based on values in the database.
{{{
SELECT Name,
CASE
WHEN Country = 'USA' THEN 'North America'
WHEN Country = 'UK' THEN 'Europe'
ELSE 'Wolrd'
END
FROM Users;
}}}
=== LIMIT ===
`LIMIT` allows us to retstrict the number or rows returned.
`SELECT * FROM users ORDER BY name DESC LIMIT 1`
=== COUNT ===
If we want just the number of rows, we can use count.
`SELECT COUNT(*) FROM users WHERE dob > '2000-01-01'`
=== math functions ===
If we want to sum the values in ONE column we can use sum
`SELECT SUM(cash_balance) FROM users`
If we want to find an average,
`SELECT AVG(price) FROM products`
== Views == == Views ==