You are on page 1of 10

Empl (empno, ename, job, mgr, hiredate, sal, comm, deptno)

Q1. Display all records from empl table.


mysql> select * from empl;
+-------+-----------+-----------+------+------------+---------+---------+-------+
| empno | ename | job
| mgr | hiredate | sal | comm | dept
no |
+-------+-----------+-----------+------+------------+---------+---------+-------+
| 8369 | SMITH | CLERK | 8902 | 1990-12-18 | 800.00 | NULL |
20 |
| 8499 | ANYA | SALESMAN | 8698 | 1991-02-20 | 1600.00 | 300.00 |
30 |
| 8521 | SETH
| SALESMAN | 8698 | 1991-02-22 | 1250.00 | 500.00 |
30 |
| 8566 | MAHADEVAN | MANAGER | 8839 | 1991-04-02 | 2985.00 | NULL |
20 |
| 8654 | MOMIN | SALESMAN | 8698 | 1991-09-28 | 1250.00 | 1400.00 |
30 |
| 8698 | BINA | MANAGER | 8839 | 1991-05-01 | 2850.00 | NULL |
30 |
| 8882 | SHIAVNSH | MANAGER | 8839 | 1991-06-09 | 2450.00 | NULL |
10 |
| 8888 | SCOTT | ANALYST | 8566 | 1992-12-09 | 3000.00 | NULL |
20 |
| 8839 | AMIR
| PRESIDENT | NULL | 1991-11-18 | 5000.00 | NULL |
10 |
| 8844 | KULDEEP | SALESMAN | 8698 | 1991-09-08 | 1500.00 | 0.00 |
30 |
| 8886 | ANOOP | CLERK | 8888 | 1993-01-12 | 1100.00 | NULL |
20 |
| 8900 | JATIN | CLERK | 8698 | 1991-12-03 | 950.00 | NULL |
30 |
| 8902 | FAKIR | ANALYST | 8566 | 1991-12-03 | 3000.00 | NULL |
20 |
| 8934 | MITA | CLERK | 8882 | 1992-01-23 | 1300.00 | NULL |
10 |
+-------+-----------+-----------+------+------------+---------+---------+-------+
14 rows in set (0.11 sec)
Q2. Display employee number and employee name from table empl.
mysql> select empno, ename from empl;
+-------+-----------+
| empno | ename |

+-------+-----------+
| 8369 | SMITH |
| 8499 | ANYA |
| 8521 | SETH
|
| 8566 | MAHADEVAN |
| 8654 | MOMIN |
| 8698 | BINA |
| 8882 | SHIAVNSH |
| 8888 | SCOTT |
| 8839 | AMIR
|
| 8844 | KULDEEP |
| 8886 | ANOOP |
| 8900 | JATIN |
| 8902 | FAKIR |
| 8934 | MITA |
+-------+-----------+
14 rows in set (0.00 sec)
Q3. Display employee name, sal added with commission for table empl.
mysql> select ename, sal+comm from empl;
+-----------+----------+
| ename | sal+comm |
+-----------+----------+
| SMITH | NULL |
| ANYA | 1900.00 |
| SETH
| 1750.00 |
| MAHADEVAN | NULL |
| MOMIN | 2650.00 |
| BINA | NULL |
| SHIAVNSH | NULL |
| SCOTT | NULL |
| AMIR
| NULL |
| KULDEEP | 1500.00 |
| ANOOP | NULL |
| JATIN | NULL |
| FAKIR | NULL |
| MITA | NULL |
+-----------+----------+
14 rows in set (0.03 sec)
Q4. Write a query to display employee name, salary and department number who are not
getting commission.
mysql> select ename, sal, deptno from empl
-> where comm is null;
+-----------+---------+--------+
| ename | sal | deptno |

+-----------+---------+--------+
| SMITH | 800.00 | 20 |
| MAHADEVAN | 2985.00 | 20 |
| BINA | 2850.00 | 30 |
| SHIAVNSH | 2450.00 | 10 |
| SCOTT | 3000.00 | 20 |
| AMIR
| 5000.00 | 10 |
| ANOOP | 1100.00 | 20 |
| JATIN | 950.00 | 30 |
| FAKIR | 3000.00 | 20 |
| MITA | 1300.00 | 10 |
+-----------+---------+--------+
10 rows in set (0.00 sec)
Q5. Write a query to display employee number, name, salary and annual salary. Label the
new column as Annual Salary.
mysql> SELECT empno, ename, sal, sal*12 as 'Annual salary' from empl;
+-------+-----------+---------+---------------+
| empno | ename | sal | Annual salary |
+-------+-----------+---------+---------------+
| 8369 | SMITH | 800.00 |
9600.00 |
| 8499 | ANYA | 1600.00 |
19200.00 |
| 8521 | SETH
| 1250.00 |
15000.00 |
| 8566 | MAHADEVAN | 2985.00 |
35820.00 |
| 8654 | MOMIN | 1250.00 |
15000.00 |
| 8698 | BINA | 2850.00 |
34200.00 |
| 8882 | SHIAVNSH | 2450.00 |
29400.00 |
| 8888 | SCOTT | 3000.00 |
36000.00 |
| 8839 | AMIR
| 5000.00 |
60000.00 |
| 8844 | KULDEEP | 1500.00 |
18000.00 |
| 8886 | ANOOP | 1100.00 |
13200.00 |
| 8900 | JATIN | 950.00 |
11400.00 |
| 8902 | FAKIR | 3000.00 |
36000.00 |
| 8934 | MITA | 1300.00 |
15600.00 |
+-------+-----------+---------+---------------+
14 rows in set (0.00 sec)
Q6. List all department numbers from empl table.
mysql> select deptno from empl;
+--------+
| deptno |
+--------+
| 20 |
| 30 |
| 30 |
| 20 |

| 30 |
| 30 |
| 10 |
| 20 |
| 10 |
| 30 |
| 20 |
| 30 |
| 20 |
| 10 |
+--------+
14 rows in set (0.00 sec)
Q7. List all unique department numbers from empl table.
mysql> select distinct deptno from empl;
+--------+
| deptno |
+--------+
| 20 |
| 30 |
| 10 |
+--------+
3 rows in set (0.03 sec)
Q8. List details of all clerks who have not been assigned any department number.
Q9. Write a command to display name and department number of the employees who are
getting commission.
mysql> select ename, deptno from empl
-> where comm is not null;
+---------+--------+
| ename | deptno |
+---------+--------+
| ANYA | 30 |
| SETH | 30 |
| MOMIN | 30 |
| KULDEEP | 30 |
+---------+--------+
4 rows in set (0.00 sec)
Q10. Display details of employees who are not getting commission.
mysql> select * from empl
-> where comm is null;
+-------+-----------+-----------+------+------------+---------+------+-------+

| empno | ename | job


| mgr | hiredate | sal | comm | deptno
|
+-------+-----------+-----------+------+------------+---------+------+-------+
| 8369 | SMITH | CLERK | 8902 | 1990-12-18 | 800.00 | NULL | 20
|
| 8566 | MAHADEVAN | MANAGER | 8839 | 1991-04-02 | 2985.00 | NULL | 20
|
| 8698 | BINA | MANAGER | 8839 | 1991-05-01 | 2850.00 | NULL | 30
|
| 8882 | SHIAVNSH | MANAGER | 8839 | 1991-06-09 | 2450.00 | NULL | 10
|
| 8888 | SCOTT | ANALYST | 8566 | 1992-12-09 | 3000.00 | NULL | 20
|
| 8839 | AMIR
| PRESIDENT | NULL | 1991-11-18 | 5000.00 | NULL | 10
|
| 8886 | ANOOP | CLERK | 8888 | 1993-01-12 | 1100.00 | NULL | 20
|
| 8900 | JATIN | CLERK | 8698 | 1991-12-03 | 950.00 | NULL | 30
|
| 8902 | FAKIR | ANALYST | 8566 | 1991-12-03 | 3000.00 | NULL | 20
|
| 8934 | MITA | CLERK | 8882 | 1992-01-23 | 1300.00 | NULL | 10
|
+-------+-----------+-----------+------+------------+---------+------+-------+
10 rows in set (0.00 sec)
Q11. Display details of employees whose name contains of four letters.
mysql> select * from empl
-> where ename like '____';
+-------+-------+-----------+------+------------+---------+--------+--------+
| empno | ename | job
| mgr | hiredate | sal | comm | deptno |
+-------+-------+-----------+------+------------+---------+--------+--------+
| 8499 | ANYA | SALESMAN | 8698 | 1991-02-20 | 1600.00 | 300.00 |

30 |

| 8521 | SETH | SALESMAN | 8698 | 1991-02-22 | 1250.00 | 500.00 |

30 |

| 8698 | BINA | MANAGER | 8839 | 1991-05-01 | 2850.00 | NULL |

30 |

| 8839 | AMIR | PRESIDENT | NULL | 1991-11-18 | 5000.00 | NULL |


| 8934 | MITA | CLERK

| 8882 | 1992-01-23 | 1300.00 | NULL |

+-------+-------+-----------+------+------------+---------+--------+--------+
5 rows in set (0.02 sec)

10 |

10 |

Q12. Display employee number, job, salary and department number for those who are in
department number 10 or 20.
mysql> select empno, job, sal, deptno from empl
-> where deptno = 10 or deptno = 20;
+-------+-----------+---------+--------+
| empno | job
| sal | deptno |
+-------+-----------+---------+--------+
| 8369 | CLERK | 800.00 | 20 |
| 8566 | MANAGER | 2985.00 | 20 |
| 8882 | MANAGER | 2450.00 | 10 |
| 8888 | ANALYST | 3000.00 | 20 |
| 8839 | PRESIDENT | 5000.00 | 10 |
| 8886 | CLERK | 1100.00 | 20 |
| 8902 | ANALYST | 3000.00 | 20 |
| 8934 | CLERK | 1300.00 | 10 |
+-------+-----------+---------+--------+
8 rows in set (0.00 sec)
Q13. Display name of all clerks who are getting salary more than 3000.
Q14. Display employee number with their salary and job who are working as
MANAGER.
mysql> select empno, sal, job from empl
-> where job = 'manager';
+-------+---------+---------+
| empno | sal | job |
+-------+---------+---------+
| 8566 | 2985.00 | MANAGER |
| 8698 | 2850.00 | MANAGER |
| 8882 | 2450.00 | MANAGER |
+-------+---------+---------+
3 rows in set (0.00 sec)
Q15. Display employee number, name, hiredate who are hired after date 1990-01-01.
mysql> select empno, ename, hiredate from empl
-> where hiredate > '1990-01-01';
+-------+-----------+------------+
| empno | ename | hiredate |
+-------+-----------+------------+
| 8369 | SMITH | 1990-12-18 |
| 8499 | ANYA | 1991-02-20 |
| 8521 | SETH
| 1991-02-22 |
| 8566 | MAHADEVAN | 1991-04-02 |
| 8654 | MOMIN | 1991-09-28 |
| 8698 | BINA | 1991-05-01 |

| 8882 | SHIAVNSH | 1991-06-09 |


| 8888 | SCOTT | 1992-12-09 |
| 8839 | AMIR
| 1991-11-18 |
| 8844 | KULDEEP | 1991-09-08 |
| 8886 | ANOOP | 1993-01-12 |
| 8900 | JATIN | 1991-12-03 |
| 8902 | FAKIR | 1991-12-03 |
| 8934 | MITA | 1992-01-23 |
+-------+-----------+------------+
14 rows in set (0.03 sec)
Q16. Write command to display structure of empl table.
mysql> desc empl;
+----------+--------------+------+-----+---------+-------+
| Field | Type
| Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| empno | decimal(4,0) | NO | | NULL |
|
| ename | varchar(10) | YES | | NULL |
|
| job
| varchar(9) | YES | | NULL |
|
| mgr
| decimal(4,0) | YES | | NULL |
|
| hiredate | date
| YES | | NULL |
|
| sal
| decimal(7,2) | YES | | NULL |
|
| comm | decimal(7,2) | YES | | NULL |
|
| deptno | decimal(2,0) | YES | | NULL |
|
+----------+--------------+------+-----+---------+-------+
8 rows in set (0.06 sec)
Q17. Display all employee names in uppercase.
mysql> select ucase(ename) from empl;
+--------------+
| ucase(ename) |
+--------------+
| SMITH
|
| ANYA
|
| SETH
|
| MAHADEVAN |
| MOMIN
|
| BINA
|
| SHIAVNSH |
| SCOTT
|
| AMIR
|
| KULDEEP |
| ANOOP
|
| JATIN
|
| FAKIR
|
| MITA
|

+--------------+
14 rows in set (0.03 sec)
Q18. Display first three letters of JOB field from empl table.
mysql> select substr(job,1,3) from empl;
+-----------------+
| substr(job,1,3) |
+-----------------+
| CLE
|
| SAL
|
| SAL
|
| MAN
|
| SAL
|
| MAN
|
| MAN
|
| ANA
|
| PRE
|
| SAL
|
| CLE
|
| CLE
|
| ANA
|
| CLE
|
+-----------------+
14 rows in set (0.03 sec)
Q19. Display three letters starting from second from names of all employees.
mysql> select substr(ename,2,3) from empl;
+-------------------+
| substr(ename,2,3) |
+-------------------+
| MIT
|
| NYA
|
| ETH
|
| AHA
|
| OMI
|
| INA
|
| HIA
|
| COT
|
| MIR
|
| ULD
|
| NOO
|
| ATI
|
| AKI
|
| ITA
|
+-------------------+
14 rows in set (0.00 sec)

Q20. Display the position of LE in JOB field.


mysql> select instr(job,'le') from empl;
+-----------------+
| instr(job,'le') |
+-----------------+
|
2|
|
3|
|
3|
|
0|
|
3|
|
0|
|
0|
|
0|
|
0|
|
3|
|
2|
|
2|
|
0|
|
2|
+-----------------+
14 rows in set (0.00 sec)
Q21. Write command to remove ? from ???? Informatics ??.
Q22. Display square root of 64 and 25.
mysql> select sqrt(64) , sqrt(25);
+----------+----------+
| sqrt(64) | sqrt(25) |
+----------+----------+
|
8|
5|
+----------+----------+
1 row in set (0.02 sec)
Q26. Find remainder when 30 is divided by 4.
mysql> select mod(30,4);
+-----------+
| mod(30,4) |
+-----------+
|
2|
+-----------+
1 row in set (0.00 sec)
Q27. Display todays date and time.
mysql> select now();
+---------------------+

| now()
|
+---------------------+
| 2009-09-13 21:08:46 |
+---------------------+
1 row in set (0.03 sec)
Q28. Display day of month for current date.
mysql> select dayofmonth(curdate());
+-----------------------+
| dayofmonth(curdate()) |
+-----------------------+
|
13 |
+-----------------------+
1 row in set (0.00 sec)
Q29. Display month number out of current date.
mysql> select month(curdate());
+------------------+
| month(curdate()) |
+------------------+
|
9|
+------------------+
1 row in set (0.01 sec)
Q30. Display day of year for current date.
mysql> select dayofyear(curdate());
+----------------------+
| dayofyear(curdate()) |
+----------------------+
|
256 |
+----------------------+
1 row in set (0.00 sec)

You might also like