1.
WQTD Emp FIRST name and LAST name from EMP table
SELECT FNAME,LNAME
FROM EMP;
-------------------------------------------------------------
2. WQTD EMP FIRST name, DOB and Designation from EMP table
SELECT FNAME, DOB,JOB
FROM EMP;
-------------------------------------------------------------
3. WQTD Emp FIRST name, DOB, MID, salary and dept number
SELECT FNAME,DOB,MGR,SAL,DNO
FROM EMP;
-------------------------------------------------------------
4. WQTD Details of emplyes from employee table
SELECT * FROM EMP;
-------------------------------------------------------------
5. WQTD EMP First name, job, Annual sal from EMP table
select fname,job,(sal*12) from emp;
-------------------------------------------------------------
6. WQTD emp name, DOJ and salary with 20000 bonus
select fname,doj,(sal+20000) from emp;
-------------------------------------------------------------
7. WQTD details of the emp along with anuual commistion
select *, (comm*12) from emp;
-------------------------------------------------------------
8. WQTD emp fname, lname, job, and sal with 10%hike
select fname,lname, job, (sal+(sal * 10/100)) from emp;
-------------------------------------------------------------
9. WQTD fm=name,lname, dno,mgr, sal with 5% deduction
select fname, lname, dno,mgr, sal-(sal * 5/100) from emp;
-------------------------------------------------------------
10. WQTD fname, lname, job, dob, sal with 14 % deduction and annual commisition
select fname, lname, dob, job,sal-(sal*14/100), (comm*12) from emp;
-------------------------------------------------------------
11. WQTD fnmae,dob, sal and annual sal with 8% hike
select fname, dob, (sal*12)+((sal*12)*8/100) from emp;
-------------------------------------------------------------
12. WQTD fname,dno, mgr,anuual commistion with 10* hike and annual sal with 4%
deduction
select fname, dno, mgr, (comm*12)+((comm*12)*10/100),(sal*12)-((sal*12)*4/100) from
emp;
-------------------------------------------------------------
13. WQTD fname, job, sal with 5% hike ,comm with 10% deduction, annual sal with 15%
hike and annual comm with 20% deduction
select fname, job, sal+(sal*5/100), comm-(comm*10/100), (sal*12)+((sal*12)*15/100),
(comm*12)-((comm*12)*20/100) from emp;
select fname, job, sal+(sal*5/100) 'Salary with 5% hike', comm-(comm*10/100)
'Commission with 10% Deduction', (sal*12)+((sal*12)*15/100) 'Annual salary with 15%
hike', (comm*12)-((comm*12)*20/100) 'Annual commission with 20% deduction' from
emp;
-------------------------------------------------------------
14. WQTD fname, lname, annual salaray from emp table
select fname 'FIRST NAME', LNAME 'LAST NAME', (SAL*12) 'ANNUAL SALARY' FROM EMP;
-------------------------------------------------------------
15. WQTD different job role present in emp table
select distinct job from emp;
-----------------------------------------------------------------------------------
---------------------------------------
16. WQTD unique combinations from sal dno
select distinct sal, dno from emp;
-----------------------------------------------------------------------------------
---------------------------------------
17. WQTD details of the employee is the lname is ending with i
select * from emp where lname like '%i';
-----------------------------------------------------------------------------------
---------------------------------------
18. WQTD fname, lname, jof if the fname contains atleast 2-A's and getting salary
more than 25,000
select fname, lname, job, sal from emp where fname like '%a%a%' and sal>25000;
-----------------------------------------------------------------------------------
---------------------------------------
19. fname, lname, job if job contains string man in it
select fname, lname, job from emp where job like '%man%';
-----------------------------------------------------------------------------------
---------------------------------------
20. WQTD details of the emps whose fname starts with s or a
select * from emp where fname like 's%' or fname like 'a%';
-----------------------------------------------------------------------------------
---------------------------------------
21. WQTD details of the emps who are hired in the year 2019
select * from emp where doj like '2019%';
-----------------------------------------------------------------------------------
---------------------------------------
22. WQTD fname lname dob if the emps who are born in the month of jan, feb or march
select fname, lname, dob from emp where dob like '_____01___%'or dob like
'_____02___' or dob like '_____03___';
or
select fname, lname, dob from emp where dob like '_____01___'or dob like
'_____02___' or dob like '_____03___';
-----------------------------------------------------------------------------------
---------------------------------------
22.WQTD details of emp those who joined in the date of 12or 01
select * from emp where doj like '%12' or doj like '%01';
-----------------------------------------------------------------------------------
---------------------------------------
23. WQTD fname,job and annual sal is the emp annual sal ends with zero
select fname,job, (sal*12) AS 'Annual salary' from emp where (sal*12) like '%0';
-----------------------------------------------------------------------------------
---------------------------------------
24. WQTD fname from emp whose fname is not starting with s
select fname from emp where fname not like 's%';
-----------------------------------------------------------------------------------
---------------------------------------
25. WQTD details of the emps if the emp not born during year 1995
select * from emp where dob not like '1995%';
-----------------------------------------------------------------------------------
---------------------------------------
26. WQTD details of the emp whose fname is not starting with s and
select * from emp where fname not like 's%' and fname not like 'd%';
-----------------------------------------------------------------------------------
---------------------------------------
27. WQTD fname lname if the lname cintsins exactly 3 characters
select fname,lname from emp where lname like '___';
-----------------------------------------------------------------------------------
---------------------------------------
28. WQTD details of the emps if the emp fname last third character is e and lname
last character is n and working as salsman or manage but not as female
select * from emp where fname like '%e__' and lname like '%n' and job
IN('SALESMAN','MANAGER') and gender='M';
-----------------------------------------------------------------------------------
---------------------------------------
29. WQTD details of the emp if the emp fname 5th charater is n and getting some
commiddion
select * from emp where fname like '____n%' and comm!='NULL';
select * from emp where fname like '____n%' and comm IS NOT 'NULL';
-----------------------------------------------------------------------------------
---------------------------------------
30. WTQD fname of the emp whose fnmae is start with vowels aeiou
select fname from emp where fname like 'a%' or fname like 'e%' or fname like 'i
%' or fname like 'o%' or fname like 'u%';
-----------------------------------------------------------------------------------
---------------------------------------
31. WQTD fname and lname if the emp lname is not ending with vowela
select fname, lname from emp where lname not like '%a' and lname not like '%e'
and lname not like '%i' and lname not like '%o' and lname not like '%u';
-----------------------------------------------------------------------------------
---------------------------------------
32. WQTD details of the emps from pentagon table if the name contains atleast one
percentaile in it
select * from pentagon where name like '%\%%';
-----------------------------------------------------------------------------------
---------------------------------------
33. WQTD details of emp from pentagon if name contains atleast 2 %
select * from pentagon where name like '%\%%\%%';
-----------------------------------------------------------------------------------
---------------------------------------
34. WQTD setails of emp from pentagon table whose name 3rd char is _
select * from pentagon where name like '__\_%';
-----------------------------------------------------------------------------------
---------------------------------------
35. WQTD max al and min sal n emp table
select max(sal), min(sal) from emp;
-----------------------------------------------------------------------------------
---------------------------------------
36. WQTD total sal given to all the sales man
select sum(sal) from emp where job='SALESMAN';
-----------------------------------------------------------------------------------
---------------------------------------
37. WQTD avg salary, total slary, min salary, amd max salary given to the emps
whose fname starts with k or r
select min(sal), max(sal), avg(sal), sum(sal) from emp where fname like 'K%' or
fname like 'r%';
-----------------------------------------------------------------------------------
---------------------------------------
38. WQTD number of emp working as salasman or manager
select count(*) from emp where job='SALESMAN' or job= 'MANAGER';
select count(*) from emp where job IN('SALESMAN','MANAGER');
-----------------------------------------------------------------------------------
---------------------------------------
39. WQTD number of emps working in dno 111 or 113 and fname is starting with r but
not as female
select count(*) from emp where dno IN(111,113) and fname like 'R%' and gender='M';
-----------------------------------------------------------------------------------
---------------------------------------
40. WQTD number of emps getting slary mor than 50,000 and born during the date 07
and getting any omm
mysql> select count(*) from emp where sal>50000 and dob like '%07' and comm is
NULL;
+----------+
-----------------------------------------------------------------------------------
---------------------------------------
41. WQTD diff job role present in emp table
select count(distinct job) from emp;
-----------------------------------------------------------------------------------
---------------------------------------
42. WQTD number of emps wporking in each dept
-----------------------------------------------------------------------------------
---------------------------------------
43. total sal spent by the company in each job role is the jon roles are salasman,
mgr, developer
select sum(sal), job from emp where job in('salesman','manager','developer') group
by(job);
-----------------------------------------------------------------------------------
---------------------------------------
44. WQTD max sal given to each dept if the emp ids getting sal more than 25,000 and
max sal more than 50,000
select max(sal),dno from emp where sal>25000 group by(dno) having max(sal)>50000;
-----------------------------------------------------------------------------------
---------------------------------------
45. WQTD ang sal and total sal given to each dept is the avg sal of the dept is
>40000
select avg(sal),sum(sal),dno from emp group by(dno) having avg(sal)>40000;
-----------------------------------------------------------------------------------
---------------------------------------
46. WQTD max sal , min sal and number od emp working in each dept if the dept
contains atleast 3 emp working in it and sal>320000
select max(sal), min(sal), count(*), dno from emp where sal>32000 group by(dno)
having count(*)>=3;
-----------------------------------------------------------------------------------
---------------------------------------
47. WQTD max sal, min sal, given to each dept if the dept has min sal more>30000
and max sal<500000
select min(sal), max(sal), dno from emp group by(dno) having min(sal)>30000 and
max(sal)<500000;
-----------------------------------------------------------------------------------
---------------------------------------
48. WQTD number of emps who are getting same salary
select count(*),sal from emp group by(sal) having count(*)>1;
+----------+-----------+
| count(*) | sal |
+----------+-----------+
| 2 | 450000.00 |
| 3 | 45000.00 |
| 2 | 30000.00 |
| 2 | 32000.00 |
+----------+-----------+
-----------------------------------------------------------------------------------
---------------------------------------
49. WQTD number of emps ha;ving same gender and working in same dept
select count(*), gender, dno from emp group by gender, dno having count(*)>1;
+----------+--------+------+
| count(*) | gender | dno |
+----------+--------+------+
| 3 | M | 111 |
| 3 | M | 110 |
| 3 | F | 113 |
+----------+--------+------+
-----------------------------------------------------------------------------------
---------------------------------------
50. WQTD details of emps according to their sal max to min
select * from emp order by(sal) DESC;
-----------------------------------------------------------------------------------
---------------------------------------
51. WQTD fname, lname, job if the mp is working as salsman or mgr and arrange the
record according to alphabetical order of their fname
select fname,lname, job from emp where job in('salesman','manager') order by fname
ASC;
-----------------------------------------------------------------------------------
---------------------------------------
52. WQTD number of emps who are getting same sal and working as same job role and
emps are getting sal more than 30000 and arrange the sal in ascending order
select count(*), sal, job from emp where sal>30000 group by sal,job having
count(*)>1 order by sal;
+----------+----------+----------+
| count(*) | sal | job |
+----------+----------+----------+
| 2 | 45000.00 | SALESMAN |
+----------+----------+----------+
-----------------------------------------------------------------------------------
---------------------------------------
53. WQTD details of first 3 emps from emp
select * from emp limit 3;
-----------------------------------------------------------------------------------
---------------------------------------
54. WQTD details of first record from emp table
select * from emp limit 1;
-----------------------------------------------------------------------------------
---------------------------------------
55. WQTD details of 2nd record from the emp table
select * from emp limit 1 offset 1;
-----------------------------------------------------------------------------------
---------------------------------------
56. WQTD 6th and 7th record from emp table
select * from emp limit 2 offset 5;
-----------------------------------------------------------------------------------
---------------------------------------
57. WQTD details of 3rd and 5th record from emp
-----------------------------------------------------------------------------------
---------------------------------------
58. WQTD details of emp boen in the year 1995 using substr function
select * from emp where substr(dob,1,4)=1995;
-----------------------------------------------------------------------------------
---------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------
58. WQTD details of top max sal holders
select * from emp order by sal desc limit 5;
-----------------------------------------------------------------------------------
---------------------------------------
59. WQTD details of last five records from amp
select * from emp order by eid desc limit 5;
-----------------------------------------------------------------------------------
---------------------------------------
60. WQTD fname, lname, doj if he emp joined in the month of April, may,june or july
select fname, lname, doj from emp where substr(doj,6,2)in (04,05,06,07);
-----------------------------------------------------------------------------------
---------------------------------------
61. WQTD fname, job,if the job is starting with sal or mana
select fname, job from emp where substr(job,1,3)='sal' or substr(job,1,4)='mana';
-----------------------------------------------------------------------------------
---------------------------------------
62. WQTD details od emp whose reversed fname matches with the string
select * from emp where reverse(fname)='nama';
-----------------------------------------------------------------------------------
---------------------------------------
63. WQTD extract initials from full name in below format
fullname : SHARUKH KHAN = S. K.
>>select concat(substr(fname,1,1),'.',substr(lname,1,1),'.') as 'FULL NAME' from
emp;
+---------------+
| FULL NAME
+---------------+
| R.M. |
| S.K. |
| J.N. |
| S.R. |
| A.G. |
| K.B. |
| M.K. |
| D.P. |
| R.G. |
| F.T. |
| P.S. |
| A.R. |
| K.R. |
+---------------+
-----------------------------------------------------------------------------------
---------------------------------------
64. WQTD first half of fname from emp
select substr(fname,1,length(fname)/2) from emp;
+---------------------------------+
| substr(fname,1,length(fname)/2) |
+---------------------------------+
| RAH |
| SAM |
| JAHA |
| SHIV |
| ABHI |
| KAR |
| MUR |
| DHAR |
| RAS |
| FAR |
| PRI |
| AM |
| KIR |
+---------------------------------+
-----------------------------------------------------------------------------------
---------------------------------------
65. WQTD 2nd half of fname
select substr(fname,length(fname)/2+1) from emp;
+---------------------------------+
| substr(fname,length(fname)/2+1) |
+---------------------------------+
| UL |
| EER |
| NVI |
| ANI |
| JIT |
| AN |
| ALI |
| ANI |
| HMI |
| IYA |
| YA |
| AN |
| AN |
+---------------------------------+
-----------------------------------------------------------------------------------
---------------------------------------
66. WQTD first half fname in lower cae and 2nd half of fname in reverse format
select concat(substr(lower(fname),1,length(fname)/2),
reverse(substr(upper(fname),length(fname)/2+1))) from emp;
+----------------------------------------------------------------------------------
---------------+
| concat(substr(lower(fname),1,length(fname)/2),
reverse(substr(upper(fname),length(fname)/2+1))) |
+----------------------------------------------------------------------------------
---------------+
| rahLU
|
| samREE
|
| jahaIVN
|
| shivINA
|
| abhiTIJ
|
| karNA
|
| murILA
|
| dharINA
|
| rasIMH
|
| farAYI
|
| priAY
|
| amNA
|
| kirNA
|
+----------------------------------------------------------------------------------
---------------+
-----------------------------------------------------------------------------------
---------------------------------------
67. WQTD fname and password >> the passwd must constain beloe conditions
1. first 3 char of fname
2. length of fname
3. last 3 digits of eid
select fname, concat(substr(fname,1,3),length(fname),substr(eid,-3,3))as 'password'
from emp;
+---------+----------+
| fname | password |
+---------+----------+
| RAHUL | RAH5701 |
| SAMEER | SAM6702 |
| JAHANVI | JAH7801 |
| SHIVANI | SHI7901 |
| ABHIJIT | ABH7902 |
| KARAN | KAR5903 |
| MURALI | MUR6001 |
| DHARANI | DHA7002 |
| RASHMI | RAS6101 |
| FARIYA | FAR6102 |
| PRIYA | PRI5103 |
| AMAN | AMA4104 |
| KIRAN | KIR5201 |
+---------+----------+
13 rows in set (0.00 sec)
-----------------------------------------------------------------------------------
---------------------------------------
68. WQTD fname, paswd, for Abhijit and Priya the paswd must contain below
conditions
1. 2nd half of fname
2. lenghth of lname
3. reversed last 3 digitd of mgr
4. last 2 digits of eid
select fname,concat(substr(fname,length(fname)/2+1), length(lname),
substr(reverse(mgr),-3,3), substr(eid,-2,2)) as 'password' from emp where fname
in('priya','abhijit');
+---------+-----------+
| fname | password |
+---------+-----------+
| ABHIJIT | JIT507102 |
| PRIYA | YA600203 |
+---------+-----------+
-----------------------------------------------------------------------------------
---------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------
69. WQTD fname, lname, job and sal if th emp are working same as dharani's job
role
select fname,lname,job from emp where job=(select job from emp where
fname='Dharani');
+---------+-------+-----------+
| fname | lname | job |
+---------+-------+-----------+
| DHARANI | PATIL | DEVELOPER |
| FARIYA | TAJ | DEVELOPER |
+---------+-------+-----------+
-----------------------------------------------------------------------------------
---------------------------------------
70. WQTD detais of the emps who are hiee before 2 years of the last hiered emp
select * from emp where 2-(select doj from emp where doj);
-----------------------------------------------------------------------------------
---------------------------------------
71. WQTD details of emp if the emp fname second char is a and emp lname last second
char is a and getting sal less than Shivani
select * from emp where fname like '_a%' and lname like '%a_' and sal<(select sal
from emp where fname='shivani');
+------+--------+-------+------------+--------+-----------+------+------------
+----------+---------+------+------+
| EID | FNAME | LNAME | DOB | GENDER | JOB | MGR | DOJ | SAL
| COMM | DNO | cid |
+------+--------+-------+------------+--------+-----------+------+------------
+----------+---------+------+------+
| 1702 | SAMEER | KHAN | 1995-04-20 | M | MANAGER | 2001 | 2017-07-07 |
90000.00 | NULL | 110 | NULL |
| 1903 | KARAN | BHAT | 1997-12-26 | M | SALESMAN | 1701 | 2019-12-26 |
45000.00 | NULL | 111 | 506 |
| 2102 | FARIYA | TAJ | 1999-01-03 | F | DEVELOPER | 2001 | 2021-03-01 |
32000.00 | 3600.00 | 113 | NULL |
+------+--------+-------+------------+--------+-----------+------+------------
+----------+---------+------+------+
-----------------------------------------------------------------------------------
---------------------------------------
72. WQTD details of emps who are acting as customer for their company and hiered
after Rahul but not as male
select * from emp where cid is not null and doj>(select doj from emp where
fname='rahul') and gender='F';
+------+---------+-------+------------+--------+--------+------+------------
+-----------+------+------+------+
| EID | FNAME | LNAME | DOB | GENDER | JOB | MGR | DOJ | SAL
| COMM | DNO | cid |
+------+---------+-------+------------+--------+--------+------+------------
+-----------+------+------+------+
| 1901 | SHIVANI | RAI | 1998-11-07 | F | TESTER | 2201 | 2019-12-12 |
450000.00 | NULL | 113 | 502 |
+------+---------+-------+------------+--------+--------+------+------------
+-----------+------+------+------+
-----------------------------------------------------------------------------------
---------------------------------------
73. WQTD details of the emps who are getting 3rd minimum salaray
select * from emp where sal=(select distinct sal from emp order by sal asc limit 1
offset 2);
+------+-------+-------+------------+--------+----------+------+------------
+----------+------+------+------+
| EID | FNAME | LNAME | DOB | GENDER | JOB | MGR | DOJ | SAL
| COMM | DNO | cid |
+------+-------+-------+------------+--------+----------+------+------------
+----------+------+------+------+
| 2104 | AMAN | RAI | 1998-08-15 | M | SALESMAN | 1701 | 2021-12-26 |
40000.00 | NULL | 111 | NULL |
+------+-------+-------+------------+--------+----------+------+------------
+----------+------+------+------+
-----------------------------------------------------------------------------------
---------------------------------------
74. WQTD details of the emps who are elder than Shivani and getting sal more than
kiran
select * from emp where dob<(select dob from emp where fname='shivani')and
sal>(select sal from emp where fname='kiran');
-----------------------------------------------------------------------------------
---------------------------------------
75.WQTD