SQL Exercises, Practice, Solution - Formatting Output
SQL [10 exercises with solution]
1. Write a SQL statement to display the commission with the percent sign ( % ) with salesman ID, name and city columns for all the salesmen. Go to the editor
Sample table: salesman
Click me to see the solution with pictorial presentation
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". Go to the editor
Sample table: orders
Click me to see the solution with pictorial presentation
3. Write a query to display the orders according to the order number arranged by ascending order. Go to the editor
Sample table: orders
Click me to see the solution with pictorial presentation
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. Go to the editor
Sample table: orders
Click me to see the solution with pictorial presentation
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. Go to the editor
Sample table: orders
Click me to see the solution with pictorial presentation
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. Go to the editor
Sample table: customer
Click me to see the solution with pictorial presentation
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. Go to the editor
Sample table: orders
Click me to see the solution with pictorial presentation
8. Write a SQL statement to display customer name, city and grade in such a manner that, the customer holding highest grade will come first. Go to the editor
Sample table: customer
Click me to see the solution with pictorial presentation
9. Write a SQL statement to make a report with customer ID in such a manner that, the largest number of orders booked by the customer will come first along with their highest purchase amount. Go to the editor
Sample table: orders
Click me to see the solution with pictorial presentation
10. Write a SQL statement to make a report with order date in such a manner that, the latest order date will come last along with the total purchase amount and total commission (15% for all salesmen) for that date. Go to the editor
Sample table : orders
Click me to see the solution with pictorial presentation
Practice Online
More to Come !
Query visualizations are generated using Postgres Explain Visualizer (pev).
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
SQL: Interview question/Tips of the Day
DML: Data Manipulation Language
DML contains statements to
- Insert data
- Delete data
- Change data
insert, delete, update
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework