-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c50b2a
commit 4990440
Showing
6 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Problem Statement: | ||
Write a SQL query to print the item name, item type of only the items which are available in shop 1 but not in shop 2 in the ascending order of item name. | ||
|
||
Information about the table: | ||
Table shop_1: | ||
+---------+------------+------------+-------+ | ||
| item_id | item_name | item_type | price | | ||
+---------+------------+------------+-------+ | ||
| 1 | pencil | stationery | 10 | | ||
| 2 | soap | toiletries | 25 | | ||
| 3 | eraser | stationery | 5 | | ||
| 4 | toothbrush | toiletries | 30 | | ||
| 5 | toothpaste | toiletries | 50 | | ||
+---------+------------+------------+-------+ | ||
|
||
Table shop_2: | ||
+---------+------------+------------+-------+ | ||
| item_id | item_name | item_type | price | | ||
+---------+------------+------------+-------+ | ||
| 1 | facewash | toiletries | 70 | | ||
| 2 | soap | toiletries | 25 | | ||
| 3 | pencil | stationery | 15 | | ||
| 4 | paintbrush | stationery | 30 | | ||
| 5 | shampoo | toiletries | 100 | | ||
+---------+------------+------------+-------+ | ||
|
||
Note: Write keywords of syntax in uppercase alphabets. | ||
|
||
Solution: | ||
SELECT item_name, item_type FROM shop_1 LEFT JOIN shop_2 | ||
USING(item_name, item_type) | ||
WHERE shop_2.item_id IS NULL | ||
ORDER BY item_name; | ||
|
||
Output: | ||
+------------+------------+ | ||
| item_name | item_type | | ||
+------------+------------+ | ||
| eraser | stationery | | ||
| toothbrush | toiletries | | ||
| toothpaste | toiletries | | ||
+------------+------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Problem Statement: | ||
Write a SQL query to print the item name, price of only the items which are available in shop 2 but not in shop 1 whose price is greater than 50. | ||
|
||
Information about the table: | ||
Table shop_1: | ||
+---------+------------+------------+-------+ | ||
| item_id | item_name | item_type | price | | ||
+---------+------------+------------+-------+ | ||
| 1 | pencil | stationery | 10 | | ||
| 2 | soap | toiletries | 25 | | ||
| 3 | eraser | stationery | 5 | | ||
| 4 | toothbrush | toiletries | 30 | | ||
| 5 | toothpaste | toiletries | 50 | | ||
+---------+------------+------------+-------+ | ||
|
||
Table shop_2: | ||
+---------+------------+------------+-------+ | ||
| item_id | item_name | item_type | price | | ||
+---------+------------+------------+-------+ | ||
| 1 | facewash | toiletries | 70 | | ||
| 2 | soap | toiletries | 25 | | ||
| 3 | pencil | stationery | 15 | | ||
| 4 | paintbrush | stationery | 30 | | ||
| 5 | shampoo | toiletries | 100 | | ||
+---------+------------+------------+-------+ | ||
|
||
Note: Write keywords of syntax in uppercase alphabets. | ||
|
||
Solution: | ||
SELECT item_name, price FROM shop_1 RIGHT JOIN shop_2 | ||
USING(item_name, price) | ||
WHERE shop_2.price>50; | ||
|
||
Output: | ||
+-----------+-------+ | ||
| item_name | price | | ||
+-----------+-------+ | ||
| facewash | 70 | | ||
| shampoo | 100 | | ||
+-----------+-------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Problem Statement: | ||
Find out all the details of employees that work for both the departments. | ||
|
||
Information about the table: | ||
Table Empdept1: | ||
+---------+----------+----------+-------------------+ | ||
| EmpCode | EmpFName | EmpLName | Job | | ||
+---------+----------+----------+-------------------+ | ||
| 9369 | TONY | STARK | SOFTWARE ENGINEER | | ||
| 9499 | TIM | ADOLF | SALESMAN | | ||
| 9566 | KIM | JARVIS | MANAGER | | ||
| 9654 | SAM | MILES | SALESMAN | | ||
+---------+----------+----------+-------------------+ | ||
|
||
Table Empdept2: | ||
+---------+----------+----------+----------+ | ||
| EmpCode | EmpFName | EmpLName | Job | | ||
+---------+----------+----------+----------+ | ||
| 9566 | KIM | JARVIS | MANAGER | | ||
| 9902 | ANDREW | FAULKNER | ANALYST | | ||
| 9685 | SAMAY | DAGA | SALESMAN | | ||
+---------+----------+----------+----------+ | ||
|
||
Note-1: The data should not contain duplicate rows of employees. | ||
Note-2: Write keywords of syntax in uppercase alphabets. | ||
|
||
Solution: | ||
SELECT DISTINCT * FROM empdept1 INNER JOIN empdept2 | ||
USING (empcode, empfname, emplname, job); | ||
|
||
Output: | ||
+---------+----------+----------+---------+ | ||
| EmpCode | EmpFName | EmpLName | Job | | ||
+---------+----------+----------+---------+ | ||
| 9566 | KIM | JARVIS | MANAGER | | ||
+---------+----------+----------+---------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Problem Statement: | ||
Write a SQL query to find the item name along with its type of stationery item which is available in both the shops. | ||
|
||
Information about the table: | ||
Table shop_1: | ||
+---------+------------+------------+-------+ | ||
| item_id | item_name | item_type | price | | ||
+---------+------------+------------+-------+ | ||
| 1 | pencil | stationery | 10 | | ||
| 2 | soap | toiletries | 25 | | ||
| 3 | eraser | stationery | 5 | | ||
| 4 | toothbrush | toiletries | 30 | | ||
| 5 | toothpaste | toiletries | 50 | | ||
+---------+------------+------------+-------+ | ||
|
||
Table shop_2: | ||
+---------+------------+------------+-------+ | ||
| item_id | item_name | item_type | price | | ||
+---------+------------+------------+-------+ | ||
| 1 | facewash | toiletries | 70 | | ||
| 2 | soap | toiletries | 25 | | ||
| 3 | pencil | stationery | 15 | | ||
| 4 | paintbrush | stationery | 30 | | ||
| 5 | shampoo | toiletries | 100 | | ||
+---------+------------+------------+-------+ | ||
|
||
Note: Write keywords of syntax in uppercase alphabets. | ||
|
||
Solution: | ||
SELECT DISTINCT item_name, item_type FROM shop_1 INNER JOIN shop_2 | ||
USING (item_name, item_type) WHERE item_type = 'stationery'; | ||
|
||
Output: | ||
+-----------+------------+ | ||
| item_name | item_type | | ||
+-----------+------------+ | ||
| pencil | stationery | | ||
+-----------+------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Problem Statement: | ||
Write a SQL query to find the name and price of items whose price is greater than 20 and available in both the shops. | ||
|
||
Information about the table: | ||
Table shop_1: | ||
+---------+------------+------------+-------+ | ||
| item_id | item_name | item_type | price | | ||
+---------+------------+------------+-------+ | ||
| 1 | pencil | stationery | 10 | | ||
| 2 | soap | toiletries | 25 | | ||
| 3 | eraser | stationery | 5 | | ||
| 4 | toothbrush | toiletries | 30 | | ||
| 5 | toothpaste | toiletries | 50 | | ||
+---------+------------+------------+-------+ | ||
|
||
Table shop_2: | ||
+---------+------------+------------+-------+ | ||
| item_id | item_name | item_type | price | | ||
+---------+------------+------------+-------+ | ||
| 1 | facewash | toiletries | 70 | | ||
| 2 | soap | toiletries | 25 | | ||
| 3 | pencil | stationery | 15 | | ||
| 4 | paintbrush | stationery | 30 | | ||
| 5 | shampoo | toiletries | 100 | | ||
+---------+------------+------------+-------+ | ||
|
||
Note: Write keywords of syntax in uppercase alphabets. | ||
|
||
Solution: | ||
SELECT DISTINCT item_name, price FROM shop_1 INNER JOIN shop_2 | ||
USING(item_name, price) WHERE price >20; | ||
|
||
Output: | ||
+-----------+-------+ | ||
| item_name | price | | ||
+-----------+-------+ | ||
| soap | 25 | | ||
+-----------+-------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Problem Statement: | ||
List down all the details of employees working in dept1 but not in Dept2. | ||
|
||
Information about the table: | ||
Table Empdept1: | ||
+---------+----------+----------+-------------------+ | ||
| EmpCode | EmpFName | EmpLName | Job | | ||
+---------+----------+----------+-------------------+ | ||
| 9369 | TONY | STARK | SOFTWARE ENGINEER | | ||
| 9499 | TIM | ADOLF | SALESMAN | | ||
| 9566 | KIM | JARVIS | MANAGER | | ||
| 9654 | SAM | MILES | SALESMAN | | ||
+---------+----------+----------+-------------------+ | ||
|
||
Table Empdept2: | ||
+---------+----------+----------+----------+ | ||
| EmpCode | EmpFName | EmpLName | Job | | ||
+---------+----------+----------+----------+ | ||
| 9566 | KIM | JARVIS | MANAGER | | ||
| 9902 | ANDREW | FAULKNER | ANALYST | | ||
| 9685 | SAMAY | DAGA | SALESMAN | | ||
+---------+----------+----------+----------+ | ||
|
||
Note: Write keywords of syntax in uppercase alphabets. | ||
|
||
Solution: | ||
SELECT * FROM empdept1 LEFT JOIN empdept2 | ||
USING (empcode, empfname, emplname, job) | ||
WHERE empdept2.empcode IS NULL; | ||
|
||
Output: | ||
+---------+----------+----------+-------------------+ | ||
| EmpCode | EmpFName | EmpLName | Job | | ||
+---------+----------+----------+-------------------+ | ||
| 9369 | TONY | STARK | SOFTWARE ENGINEER | | ||
| 9499 | TIM | ADOLF | SALESMAN | | ||
| 9654 | SAM | MILES | SALESMAN | | ||
+---------+----------+----------+-------------------+ |