Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
CREATE TABLE orders (
order_id SERIAL PRIMARY KEY,
customer_name VARCHAR(100),
order_date DATE,
total_amount DECIMAL(12,2)
);
CREATE INDEX idx_order_date
ON orders(order_date);
CREATE INDEX idx_customer_name
ON orders(customer_name);
INSERT INTO orders (customer_name, order_date, total_amount) VALUES
('Alice', '2025-01-01', 1200),
('Bob', '2025-01-05', 450),
('Alice', '2025-02-01', 850);
CREATE VIEW customer_totals AS
SELECT
customer_name,
COUNT(*) AS total_orders,
SUM(total_amount) AS revenue
FROM orders
GROUP BY customer_name;
SELECT *
FROM customer_totals
ORDER BY revenue DESC;
EXPLAIN ANALYZE
SELECT *
FROM orders
WHERE customer_name = 'Alice';Coding works best on desktop or with an external keyboard.