SQL Practicals Cs
SQL Practicals Cs
SQL Practicals Cs
SET FOREIGN_KEY_CHECKS = 0
Q1. Write a query to display ename, dname, salary and location for all employees who are not
getting bonus
SELECT ename, dname, salary, location FROM emp, dept WHERE emp.deptno=dept.deptno AND
bonus IS NULL;
Q2. Write a query to display ename, deptno, dname, salary for all employees whose location is
DELHI.
SELECT ename, emp.deptno, dname, salary FROM emp, dept WHERE emp.deptno=dept.deptno
AND location = 'DELHI';
Q3. Write a query to display gender, and number of employees in each gender.
USE yourdbname
Q1. Write a query to display pname, ward and bill for all the patients who are getting some discount.
SELECT pname, ward, bill FROM hospital WHERE discount IS NOT NULL;
Q2. Write a query to display, pname, ward and days and bill for all patients who are paying bill in the
range 8000 to 10000
SELECT pname, ward, days FROM hospital WHERE bill BETWEEN 8000 AND 10000;
Q3. Write a query to display pname, ward, days and bill for all the patients whose days are either 10
of 15
SELECT pname, ward, days, bill FROM hospital WHERE days IN(10,15);
Q4. Write a query to display pname and ward for all patients whose pname has 'm' as the third
alphabet.
SELECT pname, ward FROM hospital WHERE pname LIKE('__m%');
Q5. Write a query to display pname, ward and bill for all patients whose days are 10 and are not
getting discount.
SELECT pname, ward, bill FROM hospital WHERE days=10 AND discount IS NULL;
Practical 18: product-sale
SET FOREIGN_KEY_CHECKS = 0;
Q. WAQ to display the cname, product id , pname, and stock of all the sales whose quantity is > 10
SELECT cname, pid, pname, stock FROM sale, product WHERE sale.pid=product.prodid AND
quantity > 10;
Q. WAQ to display the cname, pname, quantity and stock for all the sales whose stock is less than
500.
SELECT cname, pname, quantity, stock FROM sale, product WHERE sale.pid=product.prodid AND
stock<500;
Q. Write a query to display pid and total price for each pid in the sales table.
SELECT pid, SUM(price) FROM sale GROUP BY pid;
Q. Write a query to display cname, quantity and price of all the sales whose price is greater than 20
and arrange the display in ascending order of price.
SELECT cname, quantity, price FROM sale WHERE price > 20 ORDER BY price DESC;
Q. Write a query to display pname and pname-wise minimum quantity in the product-sale tables.
SELECT pname, MIN(price) FROM sale, product WHERE sale.pid=product.pid GROUP BY pname;
Q. Write a query to display cname, quantity and price for all sales whose cname has an ‘O’ as second
alphabet.
SELECT cname, quantity, price FROM sales WHERE cname LIKE('_O%');
Practical 19: sportsclub
Q.1 Query to display pname, game, rating for all players who has no rating.
SELECT pname, game, rating FROM sportsclub WHERE rating IS NULL;
Q.2 Query to display pname, game, salary for all players whse salary is in the range 8000 to 10000.
SELECT pname, game, salary FROM sportsclub WHERE salary BETWEEN 8000 AND 10000;
Q.3 Query to display game, number of players in each game in the table.
SELECT game, COUNT(*) FROM sportsclub GROUP BY game;
Q.4. Write a query to display pname, game and salary for all player whose game is either cricket or
soccer.
SELECT pname, game, salary FROM sportsclub WHERE game IN('CRICKET', 'SOCCER');
Q.5 Write a query to display the pname, game and salary for all players and arrange the display in
descending order of salary.
SELECT pname, game, salary FROM sportsclub ORDER BY salary DESC;
Practical 20: Student-hobby
SET FOREIGN_KEY_CHECKS=0;
Q1. Write a query to display the student details who do not have any hobby.
SELECT * FROM student WHERE hobby IS NULL;
Q2. Write a query to display the name, age and gender for all students whose hid is either 10 or 20.
SELECT name, age, gender FROM student WHERE hid IN(10,20);
Q3. Write a query to display the name, age and class of all the students whose name starts with the
alphabet R.
SELECT name, age, class FROM student WHERE name LIKE("R%");
Q4. Write a query to display the class and number of students in each class excluding class IX.
SELECT class, COUNT(*) FROM student GROUP by class having class <>"IX";
Q5. Write a query to display the name, age and house for all students whose age is greater than 16
years.
SELECT name, age, house FROM student, housename WHERE student.hid=housename.hid AND
age>16;