Exercise 0
Function in SQL
Create a database named
practice
.Run the below queries to generate a table.
Write SQL Queries to solve for the following:
Calculate the total revenue
(Quantity * UnitPrice)
for all sales.Find the average discount given across all products.
Determine the maximum quantity sold in a single transaction.
Count the number of sales transactions in the North region.
Write a SELECT query to extract the first three characters of each product name.
Use a SELECT query to convert all salesperson names to uppercase.
Write a SELECT query to replace "Laptop" with "Notebook" in the product names.
Use a SELECT query to extract the month from each sale date.
Write a SELECT query to calculate the number of days between the earliest and latest sale dates.
Use a SELECT query to calculate the year-to-date total revenue.
Write a SELECT query to round the UnitPrice to the nearest whole number for all products.
Use a SELECT query to calculate the square of the quantity sold for each transaction.
Use a SELECT query to categorize sales as "High Value" if the revenue exceeds $1000, otherwise "Low Value."
Write a SELECT query to determine if any sales had a discount greater than 10%.
Write a SELECT query to calculate the average discount, ignoring any NULL values (simulate NULLs if needed).
Use a SELECT query to convert the SaleDate into a formatted string like YYYY-MM-DD and display it.
Write a SELECT query to cast the UnitPrice as an integer and display it.
Last updated