-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrains_Q.sql
More file actions
77 lines (57 loc) · 1.4 KB
/
Trains_Q.sql
File metadata and controls
77 lines (57 loc) · 1.4 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
create database Trains;
use Trains;
create table train_root (
RID varchar(20) Not NULL,
`Starting` VARCHAR(50) NOT NULL,
Going_through varchar(50) NOT NULL,
Destination VARCHAR(50) NOT NULL,
TID VARCHAR(20) NOT Null,
Amount Decimal(10,2) NOT NULL
);
INSERT INTO train_root (RID, `Starting`, Going_through, Destination, TID, Amount)
VALUES
('R1', 'Colombo', 'Anuradhapura', 'Jaffna', 'T03', 8000.00),
('R2', 'Colombo', 'Kandy', 'Badulla', 'T02', 9000.00),
('R3', 'Colombo', 'Panadura', 'Matara', 'T01', 6000.00);
select * from train_root;
INSERT INTO trains (TID, Train_name, Coaches)
VALUES
('T01', 'Ruhunu kumari', 15),
('T02', 'Uda rata manike', 20),
('T03', 'Yal devi', 24);
select * from trains;
create view Root_Informations as
select
RID,
CONCAT ( `Starting` , ',' , Going_through, ',', Destination) as Root ,
TID
from train_root ;
select * from Root_Informations;
create view INFO as
select
t.TID ,
t.Train_Name as name ,
r.Amount,
r.Destination
from trains t
join train_root r
on t.TID = r.TID ;
select * from INFO;
create view NEWINFO as
select
TID ,
name ,
Destination
from INFO;
select * from NEWINFO;
create view Prices as
select
Name as Train_name ,
TID,
Amount as Old_Amount ,
(Amount + (Amount*10/100) ) as New_Amount
from INFO;
select * from Prices;
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_SCHEMA = 'Trains';