-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_Views.sql
More file actions
89 lines (59 loc) · 1.57 KB
/
Copy path10_Views.sql
File metadata and controls
89 lines (59 loc) · 1.57 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
81
82
83
84
85
86
87
88
89
-- ===========================================
-- Views
-- ===========================================
-- ===========================================
-- CREATE VIEW
-- ===========================================
-- Query 1 - Create Employee Details View
CREATE VIEW employee_details AS
SELECT
employee_id,
first_name,
last_name,
salary,
department_id
FROM employees;
-- Query 2 - Create Customer Orders View
CREATE VIEW customer_orders AS
SELECT
c.customer_name,
o.order_id,
o.order_date
FROM customers c
INNER JOIN orders o
ON c.customer_id = o.customer_id;
-- Query 3 - Create Sales Report View
CREATE VIEW sales_report AS
SELECT
c.customer_name,
p.product_name,
s.quantity,
s.total_amount
FROM customers c
INNER JOIN orders o
ON c.customer_id = o.customer_id
INNER JOIN sales s
ON o.order_id = s.order_id
INNER JOIN products p
ON s.product_id = p.product_id;
-- ===========================================
-- SELECT FROM VIEW
-- ===========================================
-- Query 4 - Display Employee Details View
SELECT *
FROM employee_details;
-- Query 5 - Display Customer Orders View
SELECT *
FROM customer_orders;
-- Query 6 - Display Sales Report View
SELECT *
FROM sales_report;
-- ===========================================
-- DROP VIEW
-- ===========================================
-- Query 7 - Drop Employee Details View
DROP VIEW employee_details;
-- Query 8 - Drop Customer Orders View
DROP VIEW customer_orders;
-- Query 9 - Drop Sales Report View
DROP VIEW sales_report;