-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLQuery1.sql
More file actions
146 lines (113 loc) · 2.97 KB
/
SQLQuery1.sql
File metadata and controls
146 lines (113 loc) · 2.97 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
--Bank Management System
Create database bank
use bank
--Customer table
Create table Customer(
CustomerId int primary key,
name varchar(50),
Age int check(Age>=18),
address varchar(50),
PhoneNo int
);
--Loan table
create table Loan(
LoanNo int primary key,
loanType varchar(60),
duration int,
InterestRate float,
Amount int,
issueDate Date
);
--Bank Branch table
create table Branch(
BranchId int,
BranchName varchar(50),
BAddress varchar(50),
BPhone int,
BankCode int primary key
);
--Customer Loan table
create table CustomerLoan(
CId int,
CLoanNo int,
foreign key (CLoanNo) references Loan (LoanNo)
);
--Inserting data into customer table
insert into Customer values (1,'Usman',19,'Islamabad',03494928),
(2,'Ali',20,'Lahore',03444928),
(3,'Hanan',18,'Multan',03423928),
(4,'Kamran',21,'Gujranwala',03554928),
(5,'Kaleem',22,'Karachi',03667928);
select*from Customer
--Inserting data into Loan table
insert into Loan values (1,'Insurence',3,0.3,12000,'2025-03-12'),
(2,'For Home',2,0.9,150500,'2022-05-11'),
(3,'For car',6,0.7,120300,'2000-02-10'),
(4,'Habib',8,0.6,11000,'2019-01-09');
select*from Loan
--Inserting data into Bank branch table
insert into Branch values (1,'United Branch','Lahore',08273756,101),
(2,'Pindi Branch','RawalPindi',02883783,102),
(3,'Hassan Branch','sindh',0895522,103),
(4,'Habib Branch','Islamabad',72765254,104);
select*from branch
--Inserting data into Customer Loan table
insert into CustomerLoan values (101,1),
(1021,2),
(10211,3),
(1011,4);
select*from CustomerLoan
--query 1
select BranchId, BAddress, Bphone,BankCode
from Branch;
--Query 2
select Top 1*from Loan order by Amount DESC
--Query 3
select distinct *from Branch
--Query 4
--Youngest
select top 1 *from Customer order by Age Asc
--Oldest
select top 1 *from Customer order by Age Desc
--Query 5
select*from Loan
where duration > 1
And InterestRate not in (5000,10000)
--Query 6
select LoanNo
from Loan
where InterestRate in (8000,12000);
--Query 7
Select name
from Customer
where Age Between (18 , 35) order by Age Asc;
--query 8
select UPPer(BranchName)
From Branch
where BranchName like '%a%';
--Query 9
select name
from Customer
where name like '%s' and name like 'n%';
--Query 10
select top 3 *from Loan order By Amount DESC;
--Query 11
alter table Loan
add int fee ;
--Query 12
Alter table CustomerLoan
Drop Column CLoanNo;
--query 13
alter column
--Query 14
Select name
from Customer
where address in ('Lahore','Islamabad')
and Age > 18;
--Query 15
select InterestRate
From Loan
where InterestRate>any (select InterestRate from Loan where duration<12);
--query 16
insert into Customer values(5,'Usman',16,'Islamabad',03494928);
//we apply condition of age so that's why