The document provides 10 SQL statements to query and summarize data from sample tables. The statements include:
1) Displaying salesman data with commission as a percentage.
2) Counting the number of orders per day and formatting the output.
3) Arranging orders by order number.
4) Arranging orders by order date with latest first.
5) Arranging orders by date and purchase amount.
6) Arranging customer data by customer ID.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
18 views
Oracle SQL Excercise 5 - Formatting Output
The document provides 10 SQL statements to query and summarize data from sample tables. The statements include:
1) Displaying salesman data with commission as a percentage.
2) Counting the number of orders per day and formatting the output.
3) Arranging orders by order number.
4) Arranging orders by order date with latest first.
5) Arranging orders by date and purchase amount.
6) Arranging customer data by customer ID.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
1.
Write a SQL statement to display the commission with the
percent sign ( % ) with salesman ID, name and city columns for all the salesmen. Sample table : salesman SELECT salesman_id,name,city,commission,’%’, FROM salesman;
2. Write a SQL statement to find out the number of orders
booked for each day and display it in such a format like "For 2001-10-10 there are 15 orders". Sample table : orders SELECT ‘For ‘||ord_date as order_date, COUNT(DISTINCT ord_date)||’ orers’ as orders FROM orders GROUP BY ord_date;
3. Write a query to display the orders according to the order
number arranged by ascending order. Sample table : orders SELECT * FROM orders ORDER BY ord_no;
4.Write a SQL statement to arrange the orders according to the
order date in such a manner that the latest date will come first then previous dates. Sample table : orders SELECT * FROM orders ORDER BY ord_date desc;
5. Write a SQL statement to display the orders with all
information in such a manner that, the older order date will come first and the highest purchase amount of same day will come first. Sample table : orders SELECT * FROM orders ORDER BY ord_date ,purch_amt desc;
6. Write a SQL statement to display the customer name, city and
grade, etc. and the display will be arranged according to the smallest customer ID. Sample table : customer SELECT name,city,grade FROM customer ORDER BY customer_id; 7. Write a SQL statement to make a report with salesman ID, order date and highest purchase amount in such an arrangement that, the smallest salesman ID will come first along with their smallest order date. Sample table : orders SELECT salesman_id,ord_date,max(purch_amt) FROM orders GROUP BY salesman_id,ord_date ORDER BY salesman_id,ord_date;
8. Write a SQL statement to display customer name, city and
grade in such a manner that, the customer holding highest grade will comes first. Sample table : customer SELECT cust_name,city,grade FROM customer ORDER BY grade desc;
9. Write a SQL statement make a report with customer ID in
such a manner that, the largest number of orders booked by the customer will comes first along with their highest purchase amount. Sample table : orders SELECT customer_id, count(distinct ord_no), max(purch_amt) from orders group by customer_id ORDER BY count(distinct ord_no) desc;
10. Write a SQL statement to make a report with order date in
such a manner that, the latest order date will comes first along with the total purchase amount and total commission (15% for all salesmen) for that date. Sample table : orders SELECT ord_date , SUM(purch_amt),SUM(purch_amt)*0.15 as commission FROM orders