SQL Basics Flashcards
1
Q
SUM() function
A
SELECT SUM(col) FROM table;
2
Q
MIN() function
A
SELECT MIN(col) FROM table;
3
Q
MAX() function
A
SELECT MAX(col) FROM table;
4
Q
AVG() function
A
SELECT AVG(col) FROM table;
5
Q
COUNT() function
A
SELECT COUNT(* or col) FROM table;
6
Q
GROUP BY clause
A
SELECT col, COUNT(*) FROM table GROUP BY col;
- GROUP BY must be used with an aggregate function
- Columns in the SELECT that are not part of the aggregate function must be included in the GROUP BY clause
7
Q
HAVING clause
A
SELECT col, COUNT(*) FROM table GROUP BY col HAVING COUNT(*) > 10;
- HAVING must be used with the GROUP BY clause
- Cannot use aliases in the SELECT clause
8
Q
DISTINCT clause
A
SELECT DISTINCT col FROM table; SELECT COUNT(DISTINCT col) FROM table;
- Must be used with SELECT
- Can be combined with aggregate functions - typically COUNT
9
Q
Addition (operator)
A
+
10
Q
Subtraction (operator)
A
-
11
Q
Multiplication (operator)
A
*
12
Q
Division (operator)
A
/
13
Q
Modulus (operator)
A
%
14
Q
Exponention (operator)
A
15
Q
Negation (operator)
A
- (as a prefix, e.g. -15)