img
Question:
Published on: 25 April, 2024

Consider the following tables:

DEPT (DCODE, DNAME)

EMP (ECODE, ENAME, BASIC, DCODE, DT_JN)

Write down the SQL statements for the following:

  1. For each department, show DNAME and total basic of the employee in the department.
  2. Find out the names of the department where no person is working.
  3. Find out the names of the employees who are working in the department named as ‘ABC’.
  4. Find out the maximum basic among the employees who have joined after year 2000.
Answer:

a. SELECT DNAME, SUM(BASIC) “TOTAL” FROM DEPT, EMP WHERE DEPT.DCODE=EMP.DCODE GROUP BY DNAME;

b. SELECT DNAME FROM DEPT WHERE NOT EXISTS (SELECT * FROM EMP WHERE DEPT.DCODE=EMP.DCODE);

c. SELECT ENAME FROM EMP, DEPT WHERE EMP.DCODE=DEPT.DCODE AND DNAME=’ABC’;

 

d. SELECT MAX(BASIC) “MAX_BASIC” FROM EMP WHERE DT_JN>01JAN2000; 

 

Random questions