-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsqlquery14.sql
57 lines (51 loc) · 3.53 KB
/
sqlquery14.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
Problem Statement:
List out all the client details email address, whose age is between 25 to 35, along with the projects assigned to them in ascending order of their age and project ID. Also, use c for client_d and p for project, as alias name of tables.
Information about the table:
Table Employee:
+-------+-----------+----------+------+-------------------+-----------+-----------+
| EmpID | EmpFname | EmpLname | Age | EmailID | PhoneNo | City |
+-------+-----------+----------+------+-------------------+-----------+-----------+
| 1 | Riya | Khanna | 21 | [email protected] | 987655443 | Delhi |
| 2 | Sahil | Kumar | 32 | [email protected] | 987657643 | Mumbai |
| 3 | Vishwas | Aanand | 24 | [email protected] | 987658871 | Kolkata |
| 4 | Harleen | Kaur | 27 | [email protected] | 987677585 | Bengaluru |
| 5 | Priyanshu | Gupta | 23 | [email protected] | 956758556 | Hyderabad |
+-------+-----------+----------+------+-------------------+-----------+-----------+
Table Project:
+-----------+-------+-------------+------------------+----------+
| ProjectID | EmpID | ProjectName | ProjectStartDate | ClientID |
+-----------+-------+-------------+------------------+----------+
| 100 | 1 | pro_1 | 2021-04-21 | 3 |
| 200 | 2 | pro_2 | 2021-03-12 | 1 |
| 300 | 3 | pro_3 | 2021-01-16 | 5 |
| 400 | 3 | pro_4 | 2021-04-27 | 2 |
| 500 | 5 | pro_5 | 2021-05-01 | 4 |
| 600 | 9 | pro_6 | 2021-01-19 | 1 |
| 700 | 7 | pro_7 | 2021-08-27 | 2 |
| 800 | 8 | pro_8 | 2021-09-15 | 3 |
+-----------+-------+-------------+------------------+----------+
Table Client_d:
+----------+-------------+-------------+------+-----------------+-----------+-----------+-------+
| ClientID | ClientFname | ClientLname | Age | ClientEmailID | PhoneNo | City | EmpID |
+----------+-------------+-------------+------+-----------------+-----------+-----------+-------+
| 1 | Steve | Rogers | 47 | [email protected] | 986674443 | Kolkata | 3 |
| 2 | Dustin | Poirier | 27 | [email protected] | 996767643 | Kolkata | 3 |
| 3 | Avinash | Jain | 24 | [email protected] | 876588971 | Delhi | 1 |
| 4 | Sushant | Aggarwal | 23 | [email protected] | 744355585 | Hyderabad | 5 |
| 5 | Param | Singh | 36 | [email protected] | 674445556 | Mumbai | 2 |
+----------+-------------+-------------+------+-----------------+-----------+-----------+-------+
Note-1: Write keywords of syntax in uppercase alphabets.
Note-2: Use employee ID to link the two tables.
Solution:
SELECT c.clientid, c.clientfname, c.clientlname, c.clientemailid, p.projectid, p.projectname
FROM client_d c RIGHT JOIN project p
ON p.clientid = c.clientid
WHERE c.age BETWEEN 25 AND 35
ORDER BY c.age AND p.projectid;
Output:
+----------+-------------+-------------+----------------+-----------+-------------+
| clientid | clientfname | clientlname | clientemailid | projectid | projectname |
+----------+-------------+-------------+----------------+-----------+-------------+
| 2 | Dustin | Poirier | [email protected] | 400 | pro_4 |
| 2 | Dustin | Poirier | [email protected] | 700 | pro_7 |
+----------+-------------+-------------+----------------+-----------+-------------+