Lecture 06 - SQL Queries
Lecture 06 - SQL Queries
Management Systems
Lecture 6: SQL Queries
● Asking for an extension a few hours before (or after!) the deadline is too late
○ unless the nature of the emergency precludes being able to send a message
○ "I had the flu" does not prevent you logging in to Piazza
● "I forgot" is not an excuse.
● "I had to prepare for an interview" is not an excuse.
Alternatively:
FROM BlogPosts, BlogComments
WHERE BlogPosts.postId = BlogComments.postId
See the MySQL documentation for JOIN clauses for all the details.
● 3 + NULL
● CONCAT('xyz', NULL)
● x > 0 (when x is NULL)
If the expression in a WHERE clause evaluates to NULL for a row, that row is not
included in the result.
● <expr> IS NULL
● <expr> IS NOT NULL
● Logical operators AND, OR
NULL NULL
● <expr> IS NULL
● <expr> IS NOT NULL
● Logical operators AND, OR
● <expr> IS NULL
● <expr> IS NOT NULL
● Logical operators AND, OR
● <expr> IS NULL
● <expr> IS NOT NULL
● Logical operators AND, OR
● <expr> IS NULL
● <expr> IS NOT NULL
● Logical operators AND, OR
● <expr> IS NULL
● <expr> IS NOT NULL
● Logical operators AND, OR
● <expr> IS NULL
● <expr> IS NOT NULL
● Logical operators AND, OR
SELECT FirstName
FROM BlogUsers
GROUP BY FirstName
UserName FirstName LastName DoB FirstName
}
jy Jae Yoon 2005-01-01 Jae
● MIN(expr)
● MAX(expr)
● SUM(expr)
● AVG(expr)
● COUNT(expr): number of rows in group where value of expr is not NULL
○ COUNT(DISTINCT expr): number of distinct non-NULL values of expr in group
○ COUNT(*): number of rows in group
○ COUNT(1): effectively, number of rows in group
x y x SUM(y)
A 2 A 12
A 7 B NULL
A NULL
If argument is null for all rows, result is NULL, as
A 3 in 2nd row above.
B NULL
B NULL
x y x COUNT(y)
A 2 A 3
A 7 B 0
A NULL
B NULL
year revenue
2000 4525
2001 3010
year revenue
2000 4525
2001 3010
year revenue Here, value in rollup row is sum of previous two rows.
2001 3010 If we’d said AVG(revenue), rollup row would have been average of all
sales records from 2000 and 2001.
NULL 7535
product;
For each day in Feb 2015, how many comments were posted?