我在这里是postgres是我的查询
update cust_final_1 as cust set cust.enure_days=datediff(day,1date,current_date)
from card as card join cust_final_1 as cust on cust.cust_id=card.cardh_cust_id
left join bt_time as tim on card.cardh_act_dt=tim.time_id
执行它时会出现错误,因为"""
附近的语法不正确错误是什么
答案 0 :(得分:0)
这应该适合你:
UPDATE cust
SET cust.enure_days = datediff(day, 1 DATE, CURRENT_DATE)
FROM card AS card
INNER JOIN cust_final_1 AS cust
ON cust.cust_id = card.cardh_cust_id
LEFT JOIN bt_time AS tim
ON card.cardh_act_dt = tim.time_id
只需在UPDATE
关键字
答案 1 :(得分:0)
不确定你的专栏是什么意思,但是这里有。我假设“1date”是您希望与
区别开来的日期UPDATE cust_final_1
SET enure_days=current_date - "1date" -- datediff is not postgresql, just subtract if they are both dates
FROM card
left join bt_time as tim on card.cardh_act_dt=tim.time_id
WHERE cust_final_1.cust_id=card.cardh_cust_id
我也对左连接表示怀疑。为什么这样?如果bt_time中没有相应的记录,并且该表中有“1date”,那么您将使用NULL更新记录。我建议使用INNER JOIN,这只是意味着丢失的记录不会做任何事情。