根据我的想法,我在下面有3个查询。我不是一个sql专业版,这些是我最后的作业。
- 减少10%的产品价格至少有两个优惠| 'Tb_Offers.Prod_ID'... AGGREGATE函数或GROUP BY子句
UPDATE Tb_Offers
SET Price=CASE
WHEN Prod_ID IN (SELECT Prod_ID FROM Tb_Offers
HAVING COUNT(Tb_Offers.Prod_ID)>1) THEN 0.9
ELSE 1
END*Price
- 删除所有没有销售的优惠|说(受影响的是0行)
DELETE Tb_Offers
WHERE Prod_ID NOT IN (SELECT Tb_Product.Prod_ID FROM Tb_Transactions, Tb_Product, Tb_Offers
WHERE Tb_Product.Prod_ID = Tb_Offers.Prod_ID
AND Tb_Offers.Prod_ID = Tb_Transactions.Prod_ID)
- 将具有至少4个优惠的产品的电脑价格和价格降低20%| 'Tb_Offers.Prod_ID'... AGGREGATE函数或GROUP BY子句
UPDATE Tb_Offers
SET Price=.20*Price
WHERE Prod_ID IN
(SELECT Prod_ID
FROM Tb_Product P
WHERE CASE
WHEN Name='Computer' THEN 1
ELSE (SELECT Prod_ID
FROM Tb_Offers O
HAVING COUNT(Prod_ID)>=4)
END=1)
我有以下表格:
Tb_Consumer - 姓名,城市,Con_ID
Tb_Supplier - 名称,城市,Supp_ID
Tb_Offers - 名称,数量,Prod_ID,Supp_ID
Tb_Product - 名称,Prod_ID
Tb_Requests - 名称,数量,Prod_ID,Con_ID
Tb_Transactions - Prod_ID,Tran_ID,Supp_ID,Con_ID,数量,价格