使用以下选择并想要进行更新,但在Microsoft SQL中查找语法有点混乱,这样容易得多!
选择如下所示,我想要做的是基于此选择c.allow_to_trade =' Y'到了' N'和其他标准。
SELECT MAX(Trade_date) "TRADE DATE",
t.client,
c.shortened_name,
c.allow_to_trade "ACTIVE",
C.GCD_NUMBER
FROM lib.trades t ,
lib.client_address c
WHERE t.client = c.client
AND c.allow_to_trade = 'Y'
GROUP BY C.GCD_NUMBER,
t.client,
c.shortened_name,
c.allow_to_trade
HAVING MAX(trade_date) < '01-may-2012'
提前致谢
答案 0 :(得分:0)
可以,请你试试这个:
UPDATE lib.client_address
SET allow_to_trade='N'
WHERE client IN
(SELECT t.client
FROM lib.trades t ,
lib.client_address c
WHERE t.client = c.client
AND c.allow_to_trade = 'Y'
GROUP BY C.GCD_NUMBER,
t.client,
c.shortened_name,
c.allow_to_trade
HAVING MAX(trade_date) < '01-may-2012'
);