SQL Exercises 5 — Formatting Query Output

1. Select all the salespeople. Return salesman_id, name, city, commission with the percent sign (%).

1. 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. Find all the orders. Sort the result-set in ascending order by ord_no. Return all fields.

3. Find all the orders. Sort the result-set in descending order by ord_date. Return all fields.

4. Find all the orders. Sort the result-set in descending order by ord_date and purch_amt. Return all fields.

5. 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.

6. 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.

7. Calculate summation of purchase amount, total commission (15% for all salesmen) by each order date. Sort the result-set on order date. Return order date, summation of purchase amount and commission.

1. Find all the customers. Sort the result-set by customer_id. Return cust_name, city, grade.

2. Find all the customers. Sort the result-set in descending order on 3rd field. Return customer name, city and grade.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store