-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCount.sql
32 lines (28 loc) · 956 Bytes
/
Count.sql
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
/**
* \file Count.sql
* \brief COUNT - returns the number of records returned by a select query
*
* \note NULL values are not counted
*/
#--------------------------------------------------------------------------------------------------
SELECT
count(*),
count(-1),
count(0),
count(1),
count(2),
count(NULL)
FROM
triptake.Languages;
# count(*), count(-1), count(0), count(1), count(2), count(NULL)
# 42, 42, 42, 42, 42, 0
#--------------------------------------------------------------------------------------------------
SELECT
count(IF(status = 'Cancelled', 1, NULL)) AS 'Cancelled',
count(IF(status = 'OnHold', 1, NULL)) AS 'OnHold',
count(IF(status = 'Disputed', 1, NULL)) AS 'Disputed'
FROM
orders;
# 'Cancelled', 'OnHold', 'Disputed'
# 6, 4, 3
#--------------------------------------------------------------------------------------------------