Skip to content

Commit ffd6fdf

Browse files
committed
added all sql queries
1 parent 143c6e6 commit ffd6fdf

File tree

7 files changed

+220
-0
lines changed

7 files changed

+220
-0
lines changed

modifyingdata/sqlquery10.sql

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Problem Statement :
2+
It’s a time of recession so a new startup company has to cut down on its employee base to reduce its expenses and it has decided to remove all those employees whose name contains “an” in their name and have salary more than 100000, so update the database accordingly.
3+
4+
Information about the table
5+
Table Employee :
6+
+----+---------+-----+--------+--------+
7+
| id | name | age | gender | salary |
8+
+----+---------+-----+--------+--------+
9+
| 1 | Ryan | 21 | M | 100000 |
10+
| 2 | Joanna | 26 | F | 243200 |
11+
| 3 | Alice | 18 | M | 20000 |
12+
| 4 | Ankita | 22 | F | 100000 |
13+
| 5 | Bina | 50 | F | 700000 |
14+
| 6 | Kishore | 31 | M | 100000 |
15+
| 7 | Ali | 65 | M | 500000 |
16+
| 8 | Nina | 21 | F | 50000 |
17+
| 9 | Aman | 28 | M | 250000 |
18+
| 10 | Raj | 24 | M | 150000 |
19+
+----+---------+-----+--------+--------+
20+
Note: Print the complete table after updating the data.
21+
22+
solution:
23+
DELETE FROM Employee WHERE name LIKE '%an%' AND salary>100000;
24+
select * from employee;
25+
26+
Output:
27+
+----+---------+-----+--------+--------+
28+
| id | name | age | gender | salary |
29+
+----+---------+-----+--------+--------+
30+
| 1 | Ryan | 21 | M | 100000 |
31+
| 3 | Alice | 18 | M | 20000 |
32+
| 4 | Ankita | 22 | F | 100000 |
33+
| 5 | Bina | 50 | F | 700000 |
34+
| 6 | Kishore | 31 | M | 100000 |
35+
| 7 | Ali | 65 | M | 500000 |
36+
| 8 | Nina | 21 | F | 50000 |
37+
| 10 | Raj | 24 | M | 150000 |
38+
+----+---------+-----+--------+--------+

modifyingdata/sqlquery11.sql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Problem Statement :
2+
Data for id 103 has been incorrectly entered. As a school Data manager, you have to correct this data with the correct student name and admission data.
3+
4+
Use the Replace command. Name should be “Lawrence” and admission_date should be 2008-11-27.
5+
6+
Information about the table
7+
Table Student :
8+
+-----+--------+--------+----------------+
9+
| id | Name | gender | admission_date |
10+
+-----+--------+--------+----------------+
11+
| 101 | Muthu | M | 2015-08-26 |
12+
| 102 | Aniket | M | 2014-10-21 |
13+
| 103 | Ayush | M | 2017-10-28 |
14+
| 104 | Carla | F | 2019-10-17 |
15+
| 105 | Kone | M | 2018-12-15 |
16+
+-----+--------+--------+----------------+
17+
18+
Solution:
19+
REPLACE INTO Student(id,name,gender,admission_date)
20+
VALUE(103,"Lawrence",'M','2008-11-27');
21+
SELECT * FROM Student;
22+
23+
Output:
24+
+-----+----------+--------+----------------+
25+
| id | Name | gender | admission_date |
26+
+-----+----------+--------+----------------+
27+
| 103 | Lawrence | M | 2008-11-27 |
28+
+-----+----------+--------+----------------+

modifyingdata/sqlquery12.sql

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Problem Statement
2+
Due to multiple issues due to the wrong data insertion of a person with id 305, the company needs to replace the data with its correct information. Formulate a query for the same.
3+
4+
Correct Information is :
5+
Attribute | Correct VALUE
6+
Name | Kev
7+
insurance_amount | 1750000
8+
premium_date | 2014-09-08
9+
10+
Information about the table
11+
Table Insurance :
12+
+--------------+-------+------------------+--------------+
13+
| insurance_id | Name | insurance_amount | premium_date |
14+
+--------------+-------+------------------+--------------+
15+
| 301 | Ayush | 120000 | 2015-09-15 |
16+
| 302 | Kone | 130000 | 2015-09-30 |
17+
| 303 | John | 124500 | 2015-10-15 |
18+
| 304 | Mike | 165500 | 2015-10-30 |
19+
| 305 | Kevin | 1800 | 2015-09-15 |
20+
| 306 | Gru | 180000 | 2015-09-30 |
21+
+--------------+-------+------------------+--------------+
22+
Note: Display the table after updating
23+
24+
Solution:
25+
REPLACE INTO Insurance (insurance_id,name,insurance_amount,premium_date)
26+
VALUE(305,'Kev',1750000,'2014-09-08');
27+
SELECT * FROM Insurance;
28+
29+
Output:
30+
+--------------+-------+------------------+--------------+
31+
| insurance_id | Name | insurance_amount | premium_date |
32+
+--------------+-------+------------------+--------------+
33+
| 301 | Ayush | 120000 | 2015-09-15 |
34+
| 302 | Kone | 130000 | 2015-09-30 |
35+
| 303 | John | 124500 | 2015-10-15 |
36+
| 304 | Mike | 165500 | 2015-10-30 |
37+
| 305 | Kev | 1750000 | 2014-09-08 |
38+
| 306 | Gru | 180000 | 2015-09-30 |
39+
+--------------+-------+------------------+--------------+

modifyingdata/sqlquery13.sql

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Problem Statement
2+
Given the table cities, form a query using REPLACE, to update/add the given data:
3+
Attribute | Updated value
4+
id | 4
5+
cname | Phoenix
6+
population | 1768980
7+
8+
Information about the table
9+
Table cities :
10+
+------+----------+------------+
11+
| id | cname | population |
12+
+------+----------+------------+
13+
| 1 | chicago | 2746388 |
14+
| 2 | New York | 8483190 |
15+
| 5 | LA | 3689867 |
16+
+------+----------+------------+
17+
18+
Solution:
19+
REPLACE INTO cities(id,cname,population)
20+
VALUE(4,'Phoenix',1768980);
21+
SELECT * FROM cities;
22+
23+
Ouput:
24+
+------+----------+------------+
25+
| id | cname | population |
26+
+------+----------+------------+
27+
| 1 | chicago | 2746388 |
28+
| 2 | New York | 8483190 |
29+
| 5 | LA | 3689867 |
30+
| 4 | Phoenix | 1768980 |
31+
+------+----------+------------+

modifyingdata/sqlquery7.sql

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Problem Statement:
2+
All those bank branches which are in Delhi and Bangalore are shifted to Noida due to its increasing popularity so update the branch accordingly.
3+
4+
Information about the table:
5+
Table Bank :
6+
+----+-------+-----------+--------------+
7+
| id | Name | branch | CustomerBase |
8+
+----+-------+-----------+--------------+
9+
| 1 | HCBC | Hyderabad | 100000 |
10+
| 2 | GDFS | Bangalore | 150000 |
11+
| 3 | ZCZCQ | Delhi | 250000 |
12+
| 4 | PU | Bangalore | 28000 |
13+
| 5 | DUCO | Delhi | 56000 |
14+
| 6 | LOTAK | Mumbai | 170000 |
15+
+----+-------+-----------+--------------+
16+
17+
Solution:
18+
UPDATE Bank SET branch='Noida' WHERE branch IN ('Delhi','Bangalore');
19+
SELECT * FROM Bank;
20+
21+
Output:
22+
+----+-------+-----------+--------------+
23+
| id | Name | branch | CustomerBase |
24+
+----+-------+-----------+--------------+
25+
| 1 | HCBC | Hyderabad | 100000 |
26+
| 2 | GDFS | Noida | 150000 |
27+
| 3 | ZCZCQ | Noida | 250000 |
28+
| 4 | PU | Noida | 28000 |
29+
| 5 | DUCO | Noida | 56000 |
30+
| 6 | LOTAK | Mumbai | 170000 |
31+
+----+-------+-----------+--------------+

modifyingdata/sqlquery8.sql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Problem Statement:
2+
Consider a table named products, formulate a query deleting the record where product_id = 596 or 700.
3+
4+
Information about the table:
5+
Table products :
6+
product_id | pname | p_mfd
7+
------------+----------+------------
8+
345 | oneplus | 2021-01-01
9+
596 | iphone | 2021-07-22
10+
132 | MI | 2021-03-09
11+
482 | vivo | 2021-09-01
12+
700 | oppo | 2021-04-14
13+
Note: Print the complete table after deleting the data.
14+
15+
Solution:
16+
DELETE FROM products WHERE product_id IN (596,700);
17+
select * from products;
18+
19+
Output:
20+
DELETE 2
21+
product_id | pname | p_mfd
22+
------------+---------------+-----------
23+
345 | oneplus | 2021-01-01
24+
132 | MI | 2021-03-09
25+
482 | vivo | 2021-09-01

modifyingdata/sqlquery9.sql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Problem Statement:
2+
Someone has mistakenly added the wrong data in the table as the data only for people above Age 20 was needed. You have to remove the data of all such people whose age is less than equal to 20 years.
3+
4+
Information about the table:
5+
Table stud_data:
6+
+---------+---------+------+
7+
| roll_no | Fname | Age |
8+
+---------+---------+------+
9+
| 17 | Rishi | 23 |
10+
| 7 | Shantnu | 21 |
11+
| 10 | Ojasv | 19 |
12+
| 50 | Lokesh | 23 |
13+
| 21 | Kuldeep | 20 |
14+
+---------+---------+------+
15+
Note: Print the complete table after updating the data.
16+
17+
Solution:
18+
DELETE FROM stud_data WHERE age <=20;
19+
select * from stud_data;
20+
21+
Output:
22+
+---------+---------+------+
23+
| roll_no | Fname | Age |
24+
+---------+---------+------+
25+
| 17 | Rishi | 23 |
26+
| 7 | Shantnu | 21 |
27+
| 50 | Lokesh | 23 |
28+
+---------+---------+------+

0 commit comments

Comments
 (0)