我需要这个问题的帮助。 。编写一个包含一行输出的脚本,该输出显示“三月销售额大于四月销售额”或“四月销售额大于三月销售额”,具体取决于哪个是真的。您需要总结销售额(将其视为文法价格减去当月销售额的折扣),然后使用if / else。所以我想这样做
Use MyGuitarShop;
DECLARE @AprilSales MONEY;
DECLARE @MarchSales MONEY;
SET @AprilSales = (SELECT MONTH(Orders.OrderDate) as SalesMonth,
SUM(OrderItems.ItemPrice-OrderItems.DiscountAmount) AS TotalSales
FROM Orders,OrderItems
WHERE MONTH(Orders.OrderDate) = 4
GROUP BY MONTH(Orders.OrderDate));
SET @MarchSales = (SELECT MONTH(Orders.OrderDate) as SalesMonth,
SUM(OrderItems.ItemPrice-OrderItems.DiscountAmount) AS TotalSales
FROM Orders,OrderItems
WHERE MONTH(Orders.OrderDate) = 3
GROUP BY MONTH(Orders.OrderDate));
SELECT @AprilSales, @MarchSales
FROM Orders, OrderItems
IF @AprilSales > @MarchSales
BEGIN
PRINT 'April sales are greater than March sales.'
END;
ELSE --@MarchSales > @AprilSales
PRINT 'March sales are greater than April sales.';
但是我得到了这个错误
当EXISTS未引入子查询时,只能在选择列表中指定一个表达式。