Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

19CS39E SQL Programming

CO2

1.

(i).Display name and salary of the employees, who are drawing salary more than 2000.
(2)
(ii).Display the employee name and their department number.
(1)
(iii).Display empno, name, job of the employees whose comm is not assigned
(2)
(iv).Display the employee record whose HireDate before September 1981
(2)
(v).Display employee record whose name second letter is ‘I’
(1)
2. From the following table,
Salesman table

i) write a SQL query to find the details of those salespeople who come from the 'Paris' City or
'Rome' City. Return salesman_id, name, city, commission.

ii) write a SQL query to find the details of those salespeople who live in cities apart from ‘Paris’
and ‘Rome’. Return salesman_id, name, city, commission.

iii) write a SQL query to find the details of salespeople who get the commission in the range from
0.12 to 0.14 (begin and end values are included). Return salesman_id, name, city, and
commission.

iv) write a SQL query to find the details of those salespeople whose name starts with any letter
within ‘A’ and ‘L’ (not inclusive). Return salesman_id, name, city, commission.

3. From the following table,


iv) write a SQL query to find the details of the customers whose name begins with the
letter ‘B’. Return customer_id, cust_name, city, grade, salesman_id.

ii) write a SQL query to find the details of the customers whose names end with the letter ‘n’.
Return customer_id, cust_name, city, grade, salesman_id.
(3)

iii) write a SQL query to find the details of those salespeople whose name starts with ‘N’ and the
sixth character is ‘i’. Rests may be any character. Return salesman_id, name, city, commission
(3)
4. From the given schema
Emp(employee_id,first_name,last_name,email,phone_number,hire_date
job_id,salary,commission_pct,manager_id,department_id)
i)Write a SQL query to display the employee_id, first_name, last_name, department_id of
employees whose departmet_id is equal to 100.

ii) Write an SQL query that displays the employee_id, first_name, last_name and salary of
employees whose salary is greater than or equal to 4000.

iii) Write a SQL query displays the first_name, last_name , salary and (salary+
(salary*commission_pct)) as Net Salary of employees whose departmet_id is equal to 500.

5.

Consider the following database schema


Quotation (Quotationid, Sname, Itemcode, Quotedprice, Qdate, Qstatus)
Orders (Orderid, Quotationid, Qtyordered, Orderdate, Status, Pymtdate, Delivereddate,
Amountpaid, Pymtmode)
Empdetails (Empid, Empname, Designation, Emailid, Contactno, Worksin, Salary)

iv) Retrieve the order details like 2rdered, quotationid, status, pymtdate for those orders
where payments are not received.

ii) The management wants to increase salary of all employees by 10%. Write a query to display
empid, current salary, increased salary and incremented amount.

iii) Retrieve the designation and salary of employees without any duplication of data.
iv) Retrieve quotationid, qdate and quotedprice for quotations that are quoted in 1400 to 2150
range (not inclusive of these values).

v) Retrieve the designation and salary of all ‘Manager’ and ‘Billing Staff’ who have salary in the
range of 2500 to 5000 (both inclusive). (2)

6. From the following tables,


Customer table:

Order table:

iv) write a SQL query to find all salespersons and customer who located in ‘London’ city.
ii) write a SQL query to find distinct salesperson and their cities. Return salesperson ID and city.
(2)
iii) write a SQL query to find all those salespersons and customers who involved in inventory
management system. Return salesperson ID, customer ID.
(2)

iv) write a SQL query to minimum purchase amount from the order table.
(2)

7.

Consider the following database schema


Item (Itemcode, Itemtype, Descr, Price, Reorderlevel, Qtyonhand, Category)
Quotation (Quotationid, Sname, Itemcode, Quotedprice, Qdate, Qstatus)
Orders (Orderid, Quotationid, Qtyordered, Orderdate, Status, Pymtdate, Delivereddate,
Amountpaid, Pymtmode)
Retailoutlet (Roid, Location, Managerid)

(i) Retrieve the itemcode, descr and unit price of the items which have 'Shirt' or 'Skirt' in their
desc and their category is 'B'.
(2)
(ii) Retrieve itemcode, description and price for all items.
(iii) Retrieve the quotation id and sname of the quotations which have been either 'Accepted' or
'Rejected'

(iv) Retrieve item id, item description and price for items whose names have 'r' as the second
character.
Select itemcode, descr,price from item where descry like ”_r%” (1)
(v) Retrieve the different item types.

8. Consider the following database schema


Salesman (Sid, Sname, Location)
Product (Prodid, Pdesc, Price, Category, Discount)
Sale (Saleid, Sid, Sldate, Amount)
Saledetail (Saleid, Prodid, Quantity)

(i) Write a query to display Product Id, Product Description and Category of those products
whose category name is electronics. Do case insensitive comparison.
(ii) Write a query to display the product id, first five characters of product description and
category of those products
(iii) Write a query to display the number of sales that were made in the last 40 months
(iv) Write a query to display the product description and discount for all the products. Display the
value 'No Description' if description is not having any value i.e. NULL.

(v) Display product id, category and discount of the products which belongs to the category
‘Sports’ or ‘Apparel’ in ascending order of category and discount.

9.

Consider the following Products Table and OrderDetails Table, write a SQL Query to Products
Table

Order Details Table


i) Find the name of the all the product.

ii) Find the name of the product if all the records in the OrderDetails has Quantity either equal to
6 or 2.
(1)

iii) Find the OrderID whose maximum Quantity among all product of that OrderID is greater than
average quantity of all OrderID.
(2)
iv) Find the Distinct CategoryID of the products which have any record in OrderDetails Table.
(2)
v)Finds any records in the OrderDetails table that Quantity is equal to 9.
(2)

10. From the following table,

i) write a
SQL query to calculate total purchase amount of all orders. Return total purchase amount. 
(2)
ii) write a SQL query to calculate average purchase amount of all orders. Return average purchase
amount.
(2)
iii) write a SQL query to count the number of unique salespeople. Return number of salespeople.
(2)
iv) write a SQL query to minimum purchase amount from the order table.
(2)
CO3
1. From the following tables, 
Customer table

Order Table
i) Write a SQL query to find all the customers. Sort the result-set by customer_id. Return
cust_name, city, grade.
(2)
ii) write a SQL query to find all the customers. Sort the result-set in descending order on 3rd
field. Return customer name, city and grade.
(2)
iii) write a SQL query to calculate the maximum purchase amount generated by each sales person
for every order date. Sort the result-set by sales person id and order date in ascending order.
Return sales person id, order date and maximum purchase amount.
(2)

iv) write a SQL query to find all the orders. Sort the result-set in descending order by ord_date
and purch_amt. Return all fields.
(2)
2. Order Table

i) write a SQL query to find the number of orders booked for each day. Return the result in a
format like "For 2001-10-10 there are 15 orders"."
(2)
ii) write a SQL query to find all the orders. Sort the result-set in ascending order by ord_no.
Return all fields.
(2)
iii) write a SQL query to find all the orders. Sort the result-set in descending order by ord_date.
Return all fields.
(2)
iv) write a SQL query to count the unique orders, highest purchase amount for each customer.
Sort the result-set in descending order on 2nd field. Return customer ID, number of distinct orders
and highest purchase amount by each customer.
(2)
3. From the following tables
i) write a SQL query to find all the orders issued by the salesman 'Paul Adam'. Return ord_no,
purch_amt, ord_date, customer_id and salesman_id.
(2)
ii) write a SQL query to find all the orders, which are generated by those salespeople, who live in
the city of London.Return ord_no, purch_amt, ord_date, customer_id, salesman_id.
(2)
iii) write a SQL query to find the orders generated by the salespeople who may work for
customers whose id is 3007. Return ord_no, purch_amt, ord_date, customer_id, salesman_id.
(2)

iv) write a SQL query to find the order values greater than the average order value of 10th
October 2012. Return ord_no, purch_amt, ord_date, customer_id, salesman_id

4. From the following tables

i) write a SQL query to find all the orders generated in New York city. Return ord_no, purch_amt,
ord_date, customer_id and salesman_id.
(2)
ii) write a SQL query to find the commission of the salespeople work in Paris City. Return
commission
(2)

iii) Write a query to display all the customers whose id is 2001 below the salesman ID of Mc
Lyon.
(2)
iv) Write a SQL query to count number of customers with grades above the average grades of
New York City. Return grade and count.

5. From the given schema,


Employee(Employee_Id, First_Name, Last_Name, Email, Phone_Number, Hire_Date, Job_Id,
Salary, Commission_Pct,Manager_Id, Department_Id)

i) write a SQL query to find those employees whose first name does not contain the letter ‘M’.
Sort the result-set in ascending order by department ID. Return full name (first and last name
together), hire_date, salary and department_id.
ii) write a SQL query to find those employees whose salary is in the range of 8000, 12000 (Begin
and end values are included.) and get some commission. These employees have joined before
‘1987-06-05’ and not included in the department number 40, 120 and 70. Return all fields.
(2)

iii) From the following table, write a SQL query to find those employees who do not earn any
commission. Return full name (first and last name), and salary.
iv) write a SQL query to find those employees whose salary is in the range 9000,17000 (Begin
and end values are included). Return full name, contact details and salary.
(2)

You might also like