-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab6_11_12_2020.sql
75 lines (56 loc) · 1.32 KB
/
lab6_11_12_2020.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-- create a table
CREATE TABLE store (
no INT,
code varchar[10],
item varchar[50],
quantity INT,
price float,
discount float,
mrp float
);
-- insert some values
INSERT INTO store VALUES (1, '1it', 'floar',1,35,1,36);
INSERT INTO store VALUES (2, '2it', 'ghee',1,170,25,195);
INSERT INTO store VALUES (2, '2it', 'mathbox',4,4,.50,1.50);
INSERT INTO store VALUES (2, '2it', 'cake',1,100,5,105);
INSERT INTO store VALUES (2, '2it', 'oil',1,110,10,120);
INSERT INTO store VALUES (2, '2it', 'salt',1,9,1,10);
-- fetch some values
SELECT * FROM store;
-- output-
-- 1|1it|floar|1|35.0|1.0|36.0
-- 2|2it|ghee|1|170.0|25.0|195.0
-- 2|2it|mathbox|4|4.0|0.5|1.5
-- 2|2it|cake|1|100.0|5.0|105.0
-- 2|2it|oil|1|110.0|10.0|120.0
-- 2|2it|salt|1|9.0|1.0|10.0
CREATE VIEW DetailsView AS
SELECT item,quantity
FROM store;
SELECT * FROM DetailsView;
-- output-
-- floar|1
-- ghee|1
-- mathbox|4
-- cake|1
-- oil|1
-- salt|1
update store set quantity='2' where item="floar";
SELECT * FROM store;
-- output-
-- 1|1it|floar|2|35.0|1.0|36.0
-- 2|2it|ghee|1|170.0|25.0|195.0
-- 2|2it|mathbox|4|4.0|0.5|1.5
-- 2|2it|cake|1|100.0|5.0|105.0
-- 2|2it|oil|1|110.0|10.0|120.0
-- 2|2it|salt|1|9.0|1.0|10.0
SELECT * FROM DetailsView;
-- output-
-- floar|2
-- ghee|1
-- mathbox|4
-- cake|1
-- oil|1
-- salt|1
--delete view
DROP VIEW DetailsView;