Prashant Tripathi (Ajay Kumar Garg Engineering College) SQL Assignemnt
Prashant Tripathi (Ajay Kumar Garg Engineering College) SQL Assignemnt
1. Display specific columns like name and commission for all salesmen
2. Display salesman_id, name, city, and commission within the range more than 0.10%
and less than 0.12%.
3. Produce a list of salesman_id, name, city, and commission of each salesman who lives
in cities other than Paris and Rome.
4. Find salesmen with all other information and names starting with any letter within 'A'
and 'L' (not inclusive).
SELECT *
FROM salesman
WHERE name >= 'A' AND name < 'L';
5. Find salesmen with all other information and names starting with a letter other than
and 'L' (not inclusive).
SELECT *
FROM salesman
WHERE name < 'A' OR name >= 'L';
6. Find a customer with all information whose name begins with the letter 'B'.
SELECT *
FROM salesman
WHERE name LIKE 'B%';
b) Sample table: orders
1. Write a query to display the columns in a specific order like order date, salesman id,
order number and purchase amount from for all the orders.
2. Write a query to display distinct SalesName Name who is receiving the orders.
3. Write a SQL statement to display names and commission of salesman, who belongs to
the city of Paris.
4. Write a SQL statement to display either those orders which are not issued on date
2012-09-10 and issued by the salesman whose ID is 5005 and below or those orders
which purchase amount is 1000.00 and below.
SELECT *
FROM orders
WHERE (ord_date != '2012-09-10' AND salesman_id <= 5005) OR purch_amt
<=1000.00;
5. Write a SQL query to display order number, purchase amount, the achieved and
unachieved percentage (%) for those order which exceeds the 50% of the target value
of 6000.
1. Write a SQL statement to display all the information for those customers with a grade of 200.
SELECT *
FROM customer
WHERE grade = 200;
2. Write a SQL statement to display all the information for those customers with a grade between
200 and 300.
SELECT *
FROM customer
WHERE grade BETWEEN 200 AND 300;
3. Write a query statement to display all customers in New York who have a grade value above 100.
SELECT *
FROM customer
WHERE city = 'New York' AND grade > 100;
4. Write a SQL statement to display all customers, who are either belongs to the city New York or had
a grade above 100.
SELECT *
FROM customer
WHERE city = 'New York' OR grade > 100;
5. Write a SQL statement to display all the customers, who are either belongs to the city New York or
not had a grade above 100.
SELECT *
FROM customer
WHERE city = 'New York' OR grade <= 100;
6. Write a SQL query to display those customers who are neither belongs to the city New York nor
grade value is more than 100.
SELECT *
FROM customer
WHERE city != 'New York' AND grade <= 100;
7. Write a query to sort out those customers with all information whose ID value is within any of
3007, 3008 and 3009.
SELECT *
FROM customer
WHERE customer_id IN (3007, 3008, 3009);
8. Write a SQL statement to find all those customers with all information whose names are ending
with the letter 'n'.
SELECT *
FROM customer
WHERE cust_name LIKE '%n';
9. Write a SQL statement to find that customer with all information who gets a grade except NULL
value.
SELECT *
FROM customer
WHERE grade IS NOT NULL;
11. Write a SQL statement find the number of customers who has a Grade.
12. Write a SQL statement which selects the highest grade for each of the cities.
1. Write a SQL statement to find the names of all customers along with the salesmen who works for
them.
SELECT c.cust_name, s.name AS salesman_name
FROM customer c
JOIN salesman s ON c.salesman_id = s.salesman_id;
2. Write a SQL statement to display all those orders by the customers not located in the same cities.
SELECT o.*
FROM orders o
JOIN customer c ON o.customer_id = c.customer_id
JOIN salesman s ON o.salesman_id = s.salesman_id
WHERE c.city <> s.city;
3. Write a SQL statement to display Customer Name, SalesName, Sum of Purchase Amount.
4. Write a query that produces all customers with their name, city, salesman and commission, who
served by a salesman and the salesman works at a rate of the commission within 12% to 14%.
6. Write a SQL statement to prepare a list with salesman name, customer name and their cities for the
salesmen and customer who belongs to the same city.
1. Write a SQL statement to find the total purchase amount of all orders.
FROM orders;
2. Write a SQL statement to find the average purchase amount of all orders.
3. Write a SQL statement to find the number of salesman currently listing for all of their customers.
FROM orders
GROUP BY salesman_id;
4. Write a SQL statement to get the maximum purchase amount of all the orders.
5. Write a SQL statement to get the minimum purchase amount of all the orders.
6. Write a SQL statement to find the highest purchase amount ordered by the each customer with their ID
FROM orders
GROUP BY customer_id;
7. Write a SQL statement to find the highest purchase amount ordered by the each customer on a
particular date with their ID, order date and highest purchase amount.
FROM orders
customers who have highest purchase amount in a day is more than 2000.
FROM orders
9. Write a SQL statement to find the highest purchase amount with their ID, for only those customers
FROM orders
GROUP BY customer_id;
10. Write a SQL statement to display customer details (ID and max purchase amount) whose IDs are
within the range 3002 and 3007 and highest purchase amount is more than 1000.
FROM orders
GROUP BY customer_id
11. Write a SQL statement to find the highest purchase amount with their ID, for only those salesmen
FROM orders
GROUP BY salesman_id;
12. Write a SQL statement that counts all orders for a date August 17th, 2012.
FROM orders
1. Write a query in SQL to display the ID for those employees who did two or more jobs in the past.
SELECT employee_id
FROM job_history
GROUP BY employee_id
HAVING COUNT(DISTINCT job_id) >= 2;
SELECT *
FROM salesman
UNION
SELECT *
FROM customer