-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbetween-23.psql
37 lines (28 loc) · 1.03 KB
/
between-23.psql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
The BETWEEN operator can be used to
match a value against a range of values:
- value BETWEEN low AND high
The BETWEEN operator is the same as:
- value >= low AND value <= high
- value BETWEEN low AND high
And can also be used with the NOT statement:
- value < low and > heigh
- value NOT BETWEEN low and high
The BETWEEN operator can also be used
with dates. Note that you need to format dates in the ISO 8601 standard format,
which is YYYY-MM-DD.
- date BETWEEN '2007-01-01'
AND '2007-02-01;
*/
-- Let's look at some examples with the payment table.
-- Get all the amount columns with amount between 8 and 9
SELECT amount FROM payment
WHERE amount BETWEEN 8 AND 9;
-- Count all the amount that's not between 8 and 9.
SELECT COUNT(amount) FROM payment
WHERE amount NOT BETWEEN 8 and 9;
-- Get all the payments made between feb 1 to feb 15 2007.
SELECT * FROM payment
WHERE payment_date BETWEEN '2007-02-01' and '2007-02-15';
SELECT * FROM payment
WHERE payment_date NOT BETWEEN '2007-02-01' and '2007-02-15';