-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpair-modulo-02-09.sql
More file actions
76 lines (57 loc) · 1.76 KB
/
pair-modulo-02-09.sql
File metadata and controls
76 lines (57 loc) · 1.76 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
USE northwind;
-- CustumerID, CompanyName y Country--
SELECT *
FROM customers;
-- seleccionar las columnas de customers que nos interesan--
SELECT CustomerID, CompanyName, Country
FROM customers
WHERE Country = "UK";
-- selceccionar las columnas de orders que nos interesan--
SELECT *
FROM orders;
SELECT CustomerID, Country
FROM customers
WHERE Country = "UK";
SELECT c.CustomerID, c.CompanyName, c.Country
FROM customers AS c
INNER JOIN orders AS o
ON o.CustomerID = c.CustomerID;
SELECT c.CustomerID, c.CompanyName, c.Country, o.OrderID
FROM customers AS c
INNER JOIN orders AS o
ON o.CustomerID = c.CustomerID
GROUP BY c.Country = "UK"
HAVING COUNT(o.OrderID);
-- aqui faltaba el group by --
SELECT c.CustomerID, c.CompanyName, c.Country, COUNT(o.OrderID)
FROM customers AS c
INNER JOIN orders AS o
ON o.CustomerID = c.CustomerID
WHERE Country = "UK";
SELECT c.CustomerID, c.CompanyName, c.Country, o.OrderID
FROM customers AS c
INNER JOIN orders AS o
ON o.CustomerID = c.CustomerID
WHERE Country = "UK";
-- este es el que funciona--
SELECT c.CustomerID, c.CompanyName, COUNT(o.OrderID)
FROM customers AS c
INNER JOIN orders AS o
ON o.CustomerID = c.CustomerID
WHERE Country = "UK"
GROUP BY c.CompanyName, c.CustomerID;
-- ejercicio 2-
SELECT *
FROM orders;
SELECT c.CustomerID, c.CompanyName, o.OrderDate
FROM customers AS c
INNER JOIN orders AS o
ON o.CustomerID = c.CustomerID
WHERE Country = "UK"
GROUP BY c.CompanyName, o.OrderDate;
SELECT c.CustomerID, c.CompanyName, YEAR(o.OrderDate)
FROM customers AS c
INNER JOIN orders AS o ON o.CustomerID = c.CustomerID
INNER JOIN
WHERE Country = "UK"
GROUP BY c.CompanyName, YEAR(o.OrderDate);