-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.3.sql
48 lines (42 loc) · 1.12 KB
/
3.3.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
USE Animal_Shelter; -- For SQL Server
SELECT Adopter_Email,
COUNT(*) AS Number_Of_Adoptions
FROM Adoptions
GROUP BY Adopter_Email
ORDER BY Number_Of_Adoptions DESC;
SELECT Adopter_Email,
COUNT(*) AS Number_Of_Adoptions
FROM Adoptions
WHERE COUNT(*) > 1
GROUP BY Adopter_Email
ORDER BY Number_Of_Adoptions DESC;/*Error: cannot put aggregate functions in WHERE clause*/
SELECT Adopter_Email,
COUNT(*) AS Number_Of_Adoptions
FROM Adoptions
GROUP BY Adopter_Email
HAVING COUNT(*) > 1
ORDER BY Number_Of_Adoptions DESC;
SELECT Adopter_Email,
COUNT(*) AS Number_Of_Adoptions
FROM Adoptions
GROUP BY Adopter_Email
HAVING COUNT(*) > 1
AND
Adopter_Email NOT LIKE '%gmail.com'
ORDER BY Number_Of_Adoptions DESC;
SELECT Adopter_Email,
COUNT(*) AS Number_Of_Adoptions
FROM Adoptions
WHERE Adopter_Email NOT LIKE '%gmail.com'
GROUP BY Adopter_Email
HAVING COUNT(*) > 1
ORDER BY Number_Of_Adoptions DESC;
SELECT Adopter_Email,
COUNT(*) AS Number_Of_Adoptions
FROM Adoptions
WHERE Adopter_Email NOT LIKE '%gmail.com'
GROUP BY Adopter_Email
HAVING COUNT(*) > 1
AND
YEAR(Adoption_Date) = 2019
ORDER BY Number_Of_Adoptions DESC; /*Error*/