forked from wagnerpj42/SQL-File-Evaluation
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassignmentProperties-MySQL
135 lines (114 loc) · 3.07 KB
/
assignmentProperties-MySQL
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
CS 260, Fall 2019, Lab Test
1. (15 points)
SELECT CustID, Fname, Lname, AccClosedDate
FROM Customer C
JOIN Account A ON A.Customer = C.CustID
WHERE AccStatus = 'Closed'
AND AccOpenLocation = 'Central'
AND AccClosedDate >= '2017-03-01';
CondCompiles 10 ""
CondBasicContent 15 ""
TestRowCount 10
TestColumnCount 10
CondTableCount 10 " == 2"
CondWhereCount 10 " >= 1"
TestResultSetEqualContent 35
2-1. (16 points)
SELECT AccOpenLocation, AccStatus, COUNT(*) AS "Location/Status Ct."
FROM Account
GROUP BY AccOpenLocation, AccStatus
ORDER BY AccOpenLocation, AccStatus;
CondCompiles 15 ""
CondBasicContent 10 ""
CondGroupByCount 10 " >= 1"
CondOrderByCount 10 " >= 1"
TestColumnCount 10
TestResultSetEqualContent 45
2-2. (16 points)
SELECT DISTINCT A1.AccOpenLocation, A2.AccStatus,
COUNT(DISTINCT A3.AccNumber) AS "Location/Status Ct."
FROM Account A1
CROSS JOIN Account A2
LEFT OUTER JOIN Account A3
ON (A1.AccOpenLocation = A3.AccOpenLocation AND A2.AccStatus = A3.AccStatus)
GROUP BY A1.AccOpenLocation, A2.AccStatus
ORDER BY A1.AccOpenLocation, A2.AccStatus;
CondCompiles 15 ""
CondBasicContent 10 ""
CondGroupByCount 10 " >= 1"
CondOrderByCount 10 " >= 1"
CondJoinOuterCount 10 " >= 1"
TestColumnCount 10
TestResultSetEqualContent 35
3. (18 points)
SELECT A1.AccNumber
FROM Account A1
WHERE A1.AccBalance >
(SELECT AVG(A2.AccBalance)
FROM Account A2
WHERE A2.AccType = A1.AccType);
CondCompiles 15 ""
CondBasicContent 10 ""
CondAvgCount 10 " >= 1"
CondTableCount 10 " >= 1"
TestColumnCount 10
TestResultSetEqualContent 45
4. (18 points)
SELECT TransLocation, AVG(TransAmount) AS TransLocAvg
FROM Transaction
GROUP BY TransLocation
HAVING AVG(TransAmount) <
(SELECT AVG(TransAmount)
FROM Transaction)
ORDER BY AVG(TransAmount) DESC;
CondCompiles 15 ""
CondBasicContent 10 ""
CondAvgCount 10 " >= 3"
CondGroupByCount 10 " >= 1"
CondOrderByCount 10 " >= 1"
CondDescCount 5 " >= 1"
CondTableCount 10 " >= 1"
TestResultSetEqualContent 30
5. (16 points)
SELECT CustID, FName, LName, MAX(TransAmount) AS MaxWithdrawal
FROM Customer C
JOIN Account A ON C.CustID = A.Customer
JOIN Transaction T ON (A.AccNumber = T.AccNumber)
WHERE AccType = 'savings'
AND TransType = 'w'
GROUP BY CustID, FName, LName
ORDER BY CustID;
CondCompiles 10 ""
CondBasicContent 10 ""
CondMaxCount 10 " >= 1"
CondGroupByCount 10 " >= 1"
CondOrderByCount 10 " >= 1"
CondTableCount 10 " >= 2"
TestColumnCount 5
TestResultSetEqualContent 35
6. (17 points)
SELECT DISTINCT CustID, FName, LName
FROM Customer
WHERE Custid NOT IN
(SELECT Customer
FROM Account
WHERE AccStatus = 'Active');
CondCompiles 10 ""
CondBasicContent 15 ""
CondWhereCount 15 " >= 1"
CondSelectCount 15 " >= 2"
TestColumnCount 10
TestResultSetEqualContent 35
7. (5 points)
SELECT TransLocation, COUNT(DISTINCT A.AccNumber)
FROM Transaction T
LEFT OUTER JOIN Account A ON (T.TransLocation = A.AccOpenLocation)
GROUP BY TransLocation;
CondCompiles 10 ""
CondBasicContent 10 ""
CondJoinOuterCount 10 " >= 1"
CondGroupByCount 10 " >= 1"
CondTableCount 10 " == 2"
CondCountCount 10 " >= 1"
CondDistinctCount 10 " >= 1"
TestResultSetEqualContent 30