今天SQL题:0819期补充,由于题目较多暂缓更新。
难度系数:🌟🌟☆☆☆☆☆☆☆☆
1、题目要求
- 4)、查询每个类别的产品在过去三个月中的销售趋势(按月计算销售额的变化)
- 5)、查询每个用户的最后一次购买日期,并计算在最后一次购买日期之前的所有交易总额
2、补充数据(运行前先删除原有数据)
--Catalog表
INSERT INTO Catalog (CatalogID, CatalogName, CategoryType, UnitPrice)
VALUES
(1, 'Laptop', 'Electronics', 1200.00),
(2, 'Smartphone', 'Electronics', 800.00),
(3, 'Headphones', 'Accessories', 150.00),
(4, 'Desk Chair', 'Furniture', 250.00),
(5, 'Mouse', 'Accessories', 50.00),
(6, 'Monitor', 'Electronics', 300.00),
(7, 'Keyboard', 'Accessories', 100.00),
(8, 'Desk Lamp', 'Furniture', 80.00);--Transactions表
INSERT INTO Transactions (TransactionID, TransactionDate, UserID)
VALUES
(1, '2024-08-01', 101),
(2, '2024-08-05', 102),
(3, '2024-08-07', 101),
(4, '2024-08-10', 103),
(5, '2024-08-12', 104),
(6, '2024-08-14', 101),
(7, '2024-08-15', 105),
(8, '2024-05-10', 101),
(9, '2024-06-05', 102),
(10, '2024-06-20', 103),
(11, '2024-07-01', 104),
(12, '2024-07-15', 101),
(13, '2024-08-01', 105),
(14, '2024-08-05', 103); --TransactionDetails表
INSERT INTO TransactionDetails (DetailID, TransactionID, CatalogID, Amount, UnitCost)
VALUES
(1, 1, 1, 1, 1200.00),
(2, 1, 3, 2, 150.00),
(3, 2, 2, 1, 800.00),
(4, 3, 4, 1, 250.00),
(5, 3, 5, 3, 50.00),
(6, 4, 1, 2, 1200.00),
(7, 4, 2, 2, 800.00),
(8, 5, 7, 1, 100.00),
(9, 6, 6, 2, 300.00),
(10, 7, 8, 1, 80.00),
(11, 8, 1, 1, 1200.00),
(12, 9, 2, 2, 800.00),
(13, 10, 3, 3, 150.00),
(14, 11, 4, 1, 250.00),
(15, 12, 5, 2, 50.00),
(16, 13, 1, 1, 1200.00),
(17, 14, 3, 1, 150.00); --Users表
INSERT INTO Users (UserID, UserName, UserEmail, SignUpDate)
VALUES
(101, 'Alice Wong', 'alice.wong@example.com', '2024-07-15'),
(102, 'Bob Lee', 'bob.lee@example.com', '2024-07-20'),
(103, 'Carol Kim', 'carol.kim@example.com', '2024-08-01'),
(104, 'David Smith', 'david.smith@example.com', '2024-08-05'),
(105, 'Eva Green', 'eva.green@example.com', '2024-08-10');
3、晚上发布解题方法