-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise10.1.sql
More file actions
80 lines (58 loc) · 1.75 KB
/
Copy pathexercise10.1.sql
File metadata and controls
80 lines (58 loc) · 1.75 KB
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
/*
Exercise 10.1: Complaints
Date written: December 14, 2024
*/
USE ConsumerComplaints;
SHOW TABLES;
TABLE complaint;
-- Does ComplaintId 1200385 exixt?
SELECT *
FROM complaint
WHERE complaintId = 1200385;
-- How many Complaints are there with a ComplaintId 100,000 and 200,000?
SELECT COUNT(*)
FROM complaint
WHERE complaintId BETWEEN 100000 AND 200000;
-- What is the most common Product between ComplaintId 100,000 and 200,000?
SELECT product, COUNT(product)
FROM complaint
WHERE complaintId BETWEEN 100000 AND 200000
GROUP BY product
ORDER BY COUNT(product) DESC;
-- Did anyone submit a complaint on New Year's Day 2014?
TABLE complaint;
SELECT DateReceived
FROM complaint
WHERE dateSentToCompany = '2014-01-01';
-- Are there complaints in 2018?
SELECT *
FROM complaint
WHERE datereceived LIKE '2018&';
-- How many complaints were reported in July 2015?
SELECT *
FROM complaint
WHERE dateReceived LIKE '2015-07&';
-- Do any complaints claim to have been sent to the company (DateSentToCompany) before the complaint was received (DateRecived)?
TABLE complaint;
SELECT DateSentToCompany, DateReceived
FROM complaint
WHERE DateSentToCompany < DateReceived;
-- Find consumer complaints about companies with names that start with 'V'.
SELECT company
FROM complaint
WHERE company LIKE '%V%'
GROUP BY company;
-- Find complaints that use the word 'whom' in their ComplaintNarrative.
SELECT complaintId, ComplaintNarrative
FROM complaint
WHERE ComplaintNarrative LIKE '%whom%';
-- What are the SubmissionMethods with exactly three characters?
Table complaint;
SELECT SubmissionMethod
FROM complaint
WHERE SubmissionMethod LIKE '___'
GROUP BY SubmissionMethod;
-- Which Complaints mention 'loan' in their issue?
SELECT ComplaintId, Issue
FROM complaint
WHERE Issue LIKE '%loan%';