0% found this document useful (0 votes)
45 views

SQL Questions For Journal

This document contains a journal article written by Anjali Satish Sarode, a 12th grade student, about SQL queries. It provides 30 SQL queries with answers related to tables called DEPARTMENT and STAFF. The queries select, insert, update, delete and modify data in the tables. They perform operations like counting, filtering, ordering, grouping, joining, aggregating and modifying columns.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

SQL Questions For Journal

This document contains a journal article written by Anjali Satish Sarode, a 12th grade student, about SQL queries. It provides 30 SQL queries with answers related to tables called DEPARTMENT and STAFF. The queries select, insert, update, delete and modify data in the tables. They perform operations like counting, filtering, ordering, grouping, joining, aggregating and modifying columns.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

CS JOURNAL

BY ANJALI SATISH SARODE


XII/S2
D.A.V. PUBLIC SCHOOL, NERUL
Q6) Create a table called department having the fields

dno varchar2(5) primary key, dept char(15), city char(15), Insert the following rows in the above table.

Insert the following rows into it.

Create a table called STAFF having the fields

StNo integer primary key, Name char(15), Desgn char(15), BS float. Address char[40], dno varchar2(5)
reference key

Insert the following rows in the above table.

1 ANJALI SATISH SARODE XII/S2


1. Count and display the total number of Managers in the STAFF table.

Ans- select count(Desgn) from staff where Desgn='Manager';

2 ANJALI SATISH SARODE XII/S2


2. Display Name, StNo, BS of all Managers who get salary more than Rs 40000.

Ans- select stno,name,bs from staff where bs>40000 and desgn=’Manager’;

3. Display the total no. of Desgn listed in STAFF table.

Ans- select count(distinct(Desgn)) from STAFF;

4. Display details of Staff getting highest salary.

Ans- select * from staff where bs=(select max(bs) from staff);

5. Display details of Staff whose name start with ‘A’.

Ans- select * from staff where name like 'A___';

6. Display details of Staff whose name have the letter ‘a’ in them.

Ans- select * from staff where name like '%a%';

3 ANJALI SATISH SARODE XII/S2


7. Display details of Staff whose name has a ‘y’ in the third place.

Ans- select * from staff where name like '__y';

8. Display Name, Stcode, Bs, Comm( BS * .1 ), NS(BS + Comm), department and city of each salesman.

Ans- SELECT NAME,STNO,BS,BS*0.1 AS COMM,BS+(BS*0.1) AS NS,DEPT,CITY FROM STAFF,department


WHERE DESGN='SALESMAN' AND DEPARTMENT.DNO=STAFF.DNO;

9. Display Name, StNo, BS, allowance(10% of BS) of all Salesmen from the STAFF table.

Ans-SELECT * FROM STAFF WHERE BS*0.1=(SELECT MAX(BS*0.1) FROM STAFF WHERE DESGN='SALESMAN');

10. Display details of salesmen with highest allowance (10% of BS) from the STAFF table.

Ans- SELECT NAME,STNO,DESGN,BS,ADDRESS FROM STAFF,DEPARTMENT WHERE


STAFF.DNO=DEPARTMENT.DNO AND DEPARTMENT.DEPT=”OPERATION”;

11. Display details of employees belonging to ‘Operation’ department.

Ans- select * from department where dept='operation';

4 ANJALI SATISH SARODE XII/S2


12. Display details of employees and their department where dcode=’d02’.

Ans- select * from staff where dno='d02';

13. Display details of Employees with salary less than equal to 50000 and greater than equals to 100000.

Ans- select * from staff where bs>=50000 and bs<=100000;

14. Display number of employees in each department except for HRD.

Ans- SELECT COUNT(*) FROM STAFF, DEPARTMENT WHERE DEPT!=”HRD”;

15. Display average salary of salesman & Manager.

Ans- SELECT AVG(BS) FROM STAFF WHERE DESGN=”MANAGER”;

SELECT AVG(BS) FROM STAFF WHERE DESGN=”SALESMAN”;

5 ANJALI SATISH SARODE XII/S2


16. Display average salary for all Employees staying in Delhi.

Ans- SELECT AVG(BS) FROM STAFF,DEPARTMENT WHERE CITY="DELHI";

17. Display the designation and number of designation where number of employees are less than 2.

Ans- SELECT DESGN,COUNT(DESGN) FROM STAFF GROUP BY DESGN HAVING COUNT(DESGN)<=2;

18. create a table salesmannew where details of all the salesmen are copied.

Ans- CREATE TABLE SALESMANNEW AS (SELECT * FROM STAFF);

19. Increment salary of all salesmen by 10% in table staff.

Ans- UPDATE STAFF SET BS=BS+(0.1+BS) WHERE DESGN='SALESMAN';

20. create a view named new view which shows details of staff where BS between 40000 and 100000.

Ans- CREATE VIEW NEWVIEW AS (SELECT * FROM STAFF WHERE BS BETWEEN 40000 AND 100000);

6 ANJALI SATISH SARODE XII/S2


21. Show details of staff where names and design of staff are shown in upper case.

Ans- SELECT UPPER(NAME),UPPER(DESGN) FROM STAFF;

22. Show designation wise average and sum of salary of staff members.

Ans- SELECT DESGN, AVG(BS), SUM(BS) FROM STAFF GROUP BY DESGN;

23. Display details of all staff members in ascending order of their names.

Ans- SELECT * FROM STAFF ORDER BY NAME;

24. Display details of all staff members in descending order of their salary.

Ans- SELECT * FROM STAFF ORDER BY BS DESC;

7 ANJALI SATISH SARODE XII/S2


25. Delete details of all staff members who are not ‘salesman’.

Ans- DELETE FROM STAFF WHERE DESGN!=”SALESMAN”;

26. Undo your changes. (Rollback).

Ans- ROLLBACK;

27. Add a new column age to the staff table with the default age as 22.

Ans- ALTER TABLE STAFF ADD COLUMN AGE INT DEFAULT 22;

28. Modify the age column in staff table to make it float type.

Ans- ALTER TABLE STAFF MODIFY AGE FLOAT;

29. Drop the column age & stNo. Rollback.

Ans- ALTER TABLE STAFF DROP COLUMN AGE;

30. Change name to SName with size 20.

Ans- ALTER TABLE STAFF RENAME COLUMN NAME TO EMPNAME;

8 ANJALI SATISH SARODE XII/S2

You might also like