DBMS-3
DBMS-3
MDU , ROHTAK
PRACTICAL FILE
SEMESTER : III-C
Customer
Orders
Query 1: Display name and commission of all the salesman.
SELECT name,city
FROM salesman
WHERE city='karwar';
Table: nobel_win
Query 6: How the winner of the 1971 prize for Literature.
SELECT winner
FROM nobel_win
WHERE year = 1971
AND subject = 'Literature';
Query 7: Show all the details of the winners with first name
Louis.
year subject winner country category
1970 Physics Louis Neel France Scientist
SELECT *
FROM nobel_win
WHERE winner LIKE 'Louis%';
Query 8: Show all the winners in Physics for 1970 together
with the winner of Economics for 1971.
SELECT *
FROM nobel_win
WHERE (subject = 'Physics' AND year = 1970)
UNION
(SELECT *
FROM nobel_win
WHERE (subject = 'Economics' AND year = 1971)
);
SELECT *
FROM nobel_win
WHERE year = 1970
AND subject NOT IN ('Physiology','Economics');
Query 10: Find all the details of the Nobel winners for the
subject not started with the letter 'P' and arranged
the list as the most recent comes first, then by name in order.
SELECT *
FROM nobel_win
WHERE subject NOT LIKE 'P%'
ORDER BY year DESC, winner;
Table: item_mast
Query 11: Find the name and price of the cheapest item(s).
Display all the customers, who are either belongs to the city Mysore
or not had a grade above 1.
SELECT *
FROM customer
WHERE city = 'Mysore' OR NOT grade > 1;
Query 13: (table salesman)
SELECT *
FROM customer
WHERE cust_name LIKE '%a';
Query 15: (table salesman)
SELECT *
FROM salesman
WHERE name LIKE ‘P______V%';
find that customer with all information who does not get any
grade except NULL.
SELECT *
FROM customer
WHERE grade IS NULL;
Query 17: (table orders)
SELECT SUM(pur_amt)
FROM orders;
Find the highest grade for each of the cities of the customers.
SELECT COUNT(*)
FROM orders
WHERE order_date = '2023-12-03';
Multiple tables Joins Nested Queries
SELECT *
FROM orders
WHERE salesman_id =
(SELECT salesman_id
FROM salesman
WHERE name = 'Pranav’);
SELECT *
FROM orders
WHERE pur_amt >
(SELECT AVG(pur_amt)
FROM orders
WHERE order_date = '2023-01-04 ');
SELECT *
FROM orders
WHERE salesman_id IN
(SELECT salesman_id
FROM salesman
WHERE city ='Bengalore');
Extract the data from the orders table for the salesman who
earned the maximum commission.
Find the name and ids of all salesmen who had more than
one customer.
Write a query to find all the salesmen who worked for only
one customer.
SELECT *
FROM salesman
WHERE salesman_id IN (
SELECT DISTINCT salesman_id
FROM customer a
WHERE NOT EXISTS (
SELECT * FROM customer b
WHERE a.salesman_id = b.salesman_id
AND a.cust_name <> b.cust_name)
);
Write a query to find all the salesmen who worked for only
one customer.
SELECT *
FROM salesman
WHERE salesman_id NOT IN (
SELECT a.salesman_id
FROM customer a, customer b
WHERE a.salesman_id = b.salesman_id
AND a.cust_name <> b.cust_name);
Display all the orders that had amounts that were greater
than at least one of the orders from 2023-11-02.
SELECT *
FROM Orders
WHERE pur_amt > ANY
(SELECT pur_amt
FROM orders
WHERE order_date = '2023-11-02');
SELECT *
FROM customer
WHERE grade > ALL
(SELECT grade
FROM customer
WHERE city = 'Hubli');