Importantcspt 2
Importantcspt 2
35
There are 2 tables whose field descriptions and the table contents are given
below:
TABLE : EMP
36
mysql> INSERT INTO EMP VALUES(7499,'ALLEN','SALESMAN',7698,'2012-02-
10',6000,500,30);
mysql> INSERT INTO EMP VALUES(7521,'WARD','SALESMAN',7698,'2015-07-
10',4000,900,30);
mysql> INSERT INTO EMP VALUES(7566,'JONES','MANAGER',7698,'2010-08-
12',8000,NULL,20);
mysql> INSERT INTO EMP VALUES(7934,'JAMES','CLERK',7698,'2011-12-
12',3000,NULL,10);
TABLE:DEPT
37
mysql> insert into dept values(20,'research','dallas');
mysql> insert into dept values(30,'sales','chicago');
mysql> insert into dept values(40,'operations','boston');
Based on the above tables, write SQL commands for the following:
1. Display all the records having salary greater than 3000 from the table emp.
38
4. Display the names of employees having job field other than SALESMAN.
6. Write a query to display ename, job and sal whose salary is greater than or
equal to 3000 and job is MANAGER .
39
8. Store 100 to all employees having commission NULL.
12. Display the minimum and maximum salary with headings MINSAL
&MAXSAL respectively.
40
13. Display the jobs where number of employees is less than 3.
15. Display the name, salary and annual salary with heading
“ANNUALSALARY” of all MANAGERS.
41
16. List the names of the employees of only those employees who have their
employee number as 7934,7369,7499.
17. List the names of employees having four lettered names and ending with D.
18. List the names of employees whose names have ‘L’ in the third place.
42
20. Display the names of employees getting salary within the range 5000
and7000.
21. Display the sum and average of the salary of all the employees.
22. Display the name and job of employees in descending order of names.
23. Display the names of the employees along with the department names.
43
24. Display the names of employees who works in Chicago.
25. Display the name and location of employees who works in sales department.
44
28.Display the deptno and no of employees of each department.
***********************
45
Table:product
Field Name Type Size Constraints
p_id Varchar 20 Primary key
Pname Varchar 20 Not null
manufacturer Varchar 20 Not null
Price Integer 5
46
Contents of client table
c_id cname City p_id
01 Cosmetic Shop Delhi FW05
06 Total Health Mumbai BS01
12 Live Life Delhi SH06
15 Pretty Woman Delhi FW12
16 Dreams Bangalore TP01
47
Write MYSQL commands for the following:-
1. Display the details of those clients from Delhi.
Select * from client where city=’Delhi’;
48
4. Display the number of manufacturers available.
Select count(distinct manufacturer) from product;
49
8. Increase the price of Talcum powder by 10.
Update product set price=price+10 where pname=’Talcum Powder’;
50
13. Display the product names starting with B.
Select pname from product where pname like ‘B%’;
15.Display the product,manufacturer and price sorted by pname. For products with
same name sort by manufacturer in descending order.
51
16. Display the client names in the descending order of their cities.
Select cname from client order by city desc;
52
20. Display the number of cities of the client table.
Select count(distinct city) from client;
53
23. Display the number of different manufacturers in the product table.
Select count(distinct manufacturer) from product;
54
26. Display the number of clients from each city.
Select count(cname),city from client group by city;
55
29. Display the highest price of each manufacturer.
Select manufacturer,max(price) from product group by manufacturer;
31. Display the product.p_id,product name,client name and price of all products.
Select product.p_id,pname,cname,price from client,product where
product.p_id=client.p_id;
56
32. Display the client details with their product and price.
Select client.*,pname,price from product,client where
product.p_id=client.p_id;
35. Display the name of the client from Delhi who uses Face Wash.
Select cname from product,client where product.p_id=client.p_id and
pname=’Face Wash’ and city=’Delhi’;
57
36. Display the client name and product name of all clients.
Select cname,pname from product,client where product.p_id=client.p_id;
37. Display all the clients from Bangalore who use Talcum Powder.
Select cname from product,client where product.p_id=client.p_id and
city=’Bangalore’
and pname=’Talcum Powder’;
58
39.Display the natural join of the two tables.
Select * from client natural join product;
59