-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql11s
72 lines (65 loc) · 2.23 KB
/
sql11s
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
mysql> select * from TASTES;
+-------+---------+
| Name | Filling |
+-------+---------+
| Brown | Beef |
| Brown | Ham |
| Brown | Turkey |
| Green | Beef |
| Green | Cheese |
| Green | Turkey |
| Jones | Cheese |
+-------+---------+
7 rows in set (0.00 sec)
mysql> select * from LOCATIONS;
+-----------+---------+---------------+
| Lname | Phone | Address |
+-----------+---------+---------------+
| Buttery | 7023421 | College St |
| Lincoln | 6834523 | Lincoln Place |
| O'Neill's | 6742134 | Pearse St |
| Old Nag | 7678132 | Dame St |
+-----------+---------+---------------+
4 rows in set (0.00 sec)
mysql> select * from SANDWICHES;
+-----------+-------+---------+--------+
| Location | Bread | Filling | Price |
+-----------+-------+---------+--------+
| Lincoln | Rye | Ham | 1.2500 |
| O'Neill's | White | Cheese | 1.2000 |
| O'Neill's | Whole | Ham | 1.2500 |
| Old Nag | Rye | Beef | 1.3500 |
| Buttery | White | Cheese | 1.0000 |
| O'Neill's | White | Turkey | 1.3500 |
| Buttery | White | Ham | 1.1000 |
| Lincoln | Rye | Beef | 1.3500 |
| Lincoln | White | Ham | 1.3000 |
| Old Nag | Rye | Ham | 1.4000 |
+-----------+-------+---------+--------+
10 rows in set (0.00 sec)
mysql> select Location from SANDWICHES where Filling in (select Filling from TASTES where Name = 'Jones');
+-----------+
| Location |
+-----------+
| Buttery |
| O'Neill's |
+-----------+
2 rows in set (0.00 sec)
mysql> select Location from TASTES left join SANDWICHES on TASTES.Filling = SANDWICHES.FIlling where TASTES.name = 'Jones';
+-----------+
| Location |
+-----------+
| Buttery |
| O'Neill's |
+-----------+
2 rows in set (0.00 sec)
mysql> select SANDWICHES.Location, count(distinct(TASTES.Name)) from SANDWICHES left join TASTES on SANDWICHES.Filling = TASTES.Filling group by Location;
+-----------+------------------------------+
| Location | count(distinct(TASTES.Name)) |
+-----------+------------------------------+
| Buttery | 3 |
| Lincoln | 2 |
| O'Neill's | 3 |
| Old Nag | 2 |
+-----------+------------------------------+
4 rows in set (0.00 sec)