SQL Tutorial 17: Write a query for Microsoft to aggregate completed orders amounts.

preview_player
Показать описание

In this video, we dive into an SQL query that helps you calculate important metrics for your business, such as:

1. Total number of completed orders
2. Total revenue generated from completed orders
3. Average order amount for completed orders

We’ll also show you how to handle decimal precision for the average order amount using the ROUND() and CAST() functions in SQL.

This tutorial is perfect for those looking to work with aggregations like COUNT(), SUM(), and AVG() while ensuring the right formatting for your results.

Schema:

CREATE TABLE orders_a (
order_id INT IDENTITY(1,1) PRIMARY KEY,
customer_name VARCHAR(50),
order_date DATE,
amount DECIMAL(10,2),
status VARCHAR(20)
);

INSERT INTO orders_a (customer_name, order_date, amount, status)
VALUES
('Alice', '2024-01-05', 150.00, 'Completed'),
('Bob', '2024-02-10', 200.50, 'Pending'),
('Charlie', '2024-01-15', 350.75, 'Completed'),
('David', '2024-03-01', 99.99, 'Cancelled'),
('Eve', '2024-02-20', 275.40, 'Completed');

-- Expected Output:

-- total_completed_orders total_revenue avg_order_amount
-- 3 776.15 258.72

Don’t forget to like, share, and subscribe for more SQL tutorials!

Relevant Hashtags: #SQL #SQLTutorial #SQLQuery #Database #SQLForBeginners #DataAnalytics #SQLAggregation #SQLFunctions #DatabaseManagement #SQLJoin #SQLTips #SQLCommands #SQLTraining #SQLServer #DatabaseQuery #SQLAverage #SQLSum #SQLCount #SQLCast #SQLPrecision #SQLTech
Рекомендации по теме