Lecture 25 SQL II
- Questions
- Review
- Row represents each data point
- Column corresponds to a features of each data point
- Querying a database
- SELECT Query
- Numerical and String Expressions
- Expressions
- Don’t necessarily have to SELECT information directly from columns in SQL
- Can use || to concatenate strings together
- Create numeric expressions that do operations on our data
- Transforming values: ABS(), ROUND(), NOT, -
- <> is equivalent to !=
- Selecting substrings: SUBSTR()
- SUBSTR(city, 1, 3)
- [1-3] Inclusive
- Aggregate Functions
- Allow us to compare across all the rows in a table
- MAX()
- Mixing Aggregation and Single Values
- If we include a non-aggregated column, SQL will still fill that column with a value
- SELECT city, MIN(pop_2020) FROM pop_area_2010;
- Grouping
- Creating Tables from Tables
- Grouping
- We can divide our table into groups, then aggregate within those groups, instead of aggregating across entire table
- Using sum or average, it can just take an arbitrary song name
- Grouping by expressions
- Final Query Structure and Order of Operations
SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY
LIMIT
- Database Connections
1.