Practical 4
Practical 4
(1) Write a query to display the current date. Label the column Date
QUERY:
SELECT CURRENT_DATE() AS DATE;
(2) For each employee, display the employee number, job, salary, and
salary increased by 15% and expressed as a whole number. Label the
column New Salary
QUERY:
UPDATE EMPLOYEE SET NEW_SALARY = 1.15*EMP_SAL;
(3) Modify your query no (2) to add a column that subtracts the old
salary from the new salary. Label the column Increase
QUERY:
ALTER TABLE EMPLOYEE ADD NEW_SALARY INT(8), INCREASE INT(8)
UPDATE EMPLOYEE SET NEW_SALARY = 1.15*EMP_SAL,
INCREASE=NEW_SALARY-EMP_SAL;
(4) Write a query that displays the employee’s names with the first
letter capitalized and all other letters lowercase, and the length of the
names, for all employees whose name starts with J, A, or M. Give each
column an appropriate label. Sort the results by the employees’
names.
QUERY:
SELECT
CONCAT(UPPER(SUBSTR(EMP_NAME,1,1)),LOWER(SUBSTR(EMP_NAME,
2))) AS QNAME, LENGTH(EMP_NAME) AS QLEN FROM EMPLOYEE
WHERE EMP_NAME LIKE 'J%' OR EMP_NAME LIKE 'A%' OR EMP_NAME
LIKE 'M%';
(5) Write a query that produces the following for each employee:
<employee name> earns <salary> monthly
QUERY:
SELECT CONCAT(EMP_NAME," EARNS ",EMP_SAL," MONTHLY") AS
STATEMENT FROM EMPLOYEE;