-
Notifications
You must be signed in to change notification settings - Fork 0
/
module-6-SHAPING.sql
88 lines (77 loc) · 1.58 KB
/
module-6-SHAPING.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
SELECT
p.person_first_name,
p.person_last_name
FROM
person p
WHERE
p.person_last_name IS NOT NULL
ORDER BY
p.person_last_name;
SELECT
COUNT(p.person_last_name)
FROM
person p;
SELECT
SUM(p.person_contacted_number) AS times_contact_was_made_overall
FROM
person p;
SELECT
MAX(p.person_date_last_contacted) AS most_recent_contact
FROM
person p;
SELECT
MIN(p.person_date_added) AS oldest_customer_since
FROM
person p
WHERE
p.person_date_last_contacted <> '0000-00-00 00:00:00';
SELECT
COUNT(p.person_id) AS customers,
AVG(p.person_contacted_number) AS average_of_contacts_per_customer
FROM
person p
WHERE
p.person_date_last_contacted <> '0000-00-00 00:00:00';
SELECT
(SUM(p.person_contacted_number)) / (COUNT(p.person_id)) AS average_of_contacts_without_AVG
FROM
person p;
/* Will ignore the NULL values
regardless of what the WHERE says */
SELECT COUNT(p.person_last_name)
FROM person p
WHERE p.person_last_name IS NULL;
SELECT
p.person_first_name,
COUNT(DISTINCT p.person_first_name) AS 'unique_first_names'
FROM
person p
GROUP BY
p.person_first_name;
SELECT
p.person_first_name,
COUNT(p.person_first_name) AS 'how_many_of_each_first_name'
FROM
person p
GROUP BY
p.person_first_name
ORDER BY
COUNT(p.person_first_name) DESC;
SELECT
COUNT(*) AS 'how_many_people_contacted_x_times',
p.person_contacted_number
FROM
person p
GROUP BY
p.person_contacted_number
ORDER BY
COUNT(*) DESC;
SELECT
COUNT(p.person_id) AS FirstNameCount,
p.person_first_name AS FirstName
FROM
person p
GROUP BY
p.person_first_name
HAVING
FirstNameCount > 1;