SQL Basics Flashcards

1
Q

SUM() function

A
SELECT SUM(col)
FROM table;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

MIN() function

A
SELECT MIN(col)
FROM table;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

MAX() function

A
SELECT MAX(col)
FROM table;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

AVG() function

A
SELECT AVG(col)
FROM table;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

COUNT() function

A
SELECT COUNT(* or col)
FROM table;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Addition (operator)

A

+

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Subtraction (operator)

A

-

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Multiplication (operator)

A

*

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Division (operator)

A

/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Modulus (operator)

A

%

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Exponention (operator)

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Negation (operator)

A
  • (as a prefix, e.g. -15)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Filter even numbers

A

WHERE col % 2 = 0

17
Q

Filter odd numbers

A

WHERE col % = 1

18
Q
A