postgres update join不会更新任何记录

时间:2012-09-03 07:10:34

标签: postgresql

执行以下查询时,daily_subscriptions_stats表中的记录不会更新:

UPDATE daily_subscriptions_stats dss SET arrivals_count = da.arrivals_count
FROM daily_arrivals da
WHERE da.year = dss.year AND da.month = dss.month AND da.day = dss.day

daily_subscriptions_stats中的列如下:

consecutive_day, bigint
date, timestamp
arrivals_count, integer
departures_count, integer
year, integer
month, integer
day, integer

在daily_arrivals中以下内容:

year, integer
month, integer
day, integer
arrivals_count, integer

有谁知道查询为什么不更新记录?

谢谢!

1 个答案:

答案 0 :(得分:2)

尝试使用:

UPDATE daily_subscriptions_stats dss SET arrivals_count =(SELECT da.arrivals_count
FROM daily_arrivals da
WHERE da.year = dss.year AND da.month = dss.month AND da.day = dss.day);

Here is the working SQL Fiddle