我有两个数据表成员和交易
样品:
成员
Members_Id | Name | Adress |rental_amount |
---------------------------------------------
A01 | John | New York | 4 |
A02 | Mark | German | 2 |
A03 | Ika | France | 5 |
交易
NumberTransac |Number_plate| Discount| Price |Members_Id |
---------------------------------------------------------------
1 | AA8866DG | 0 | $90000 | A01 |
2 | AB5536HG | 0 | $8000 | A01 |
3 | BG7677HJ | 0 | $70000 | A03 |
我想计算字段rental_amount和折扣 使用CASE
如果租金数量> 3然后字段“Discount”将被添加'100000'
IF (SELECT COUNT(*) FROM Members.rental_amount WHERE ) > 3 INSERT INTO Transaction(Discount) VALUES ('100000') ELSE INSERT INTO Transaction(Discount) VALUES ('100000') ; GO
我仍然感到困惑,如果sql中的设备如果...请帮帮我..谢谢
答案 0 :(得分:0)
使用UPDATE
声明:
UPDATE transaction
SET discount = 100000
WHERE Members_Id IN
(SELECT Members_Id
FROM members
WHERE rental_amount > 3 )