读书人

sql有关问题请帮下忙多谢啦。

发布时间: 2012-05-11 12:55:37 作者: rapoo

sql问题,大虾请帮下忙,谢谢啦。。。
Plan表
Plan_id Does_receive_data Receive_data_time
1
2
Plan_detail表
Plan_id Pda_receive_product_id Setting_time

1 1 2012.02

1 null 2012.05

2 1 2012.02

2 1 2012.03

写一个sql实现:若Plan_detail表中当相同的Plan_id时Pda_receive_product_id都不为null时,更新Does_receive_data为1, Receive_data_time为最大的Setting_time(plan_id为1,则为2012.05,plan_id为2,则为2012.03)


[解决办法]

SQL code
update aset a.Does_receive_data = 1,    a.Receive_data_time = (select max(Setting_time) from from Plan_detail where Plan_id = a.Plan_id)from Plan a where not exists (select 1 from Plan_detail                   where Plan_id = a.Plan_id and Pda_receive_product_id is null)
[解决办法]
探讨

SQL code

update a
set a.Does_receive_data = 1,
a.Receive_data_time = (select max(Setting_time) from from Plan_detail where Plan_id = a.Plan_id)
from Plan a
where not exists (select 1 from Plan……

读书人网 >SQL Server

热点推荐