当前位置: 代码迷 >> Sql Server >> sql有关问题,请帮下忙,多谢啦。
  详细解决方案

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

热度:64   发布时间:2016-04-27 12:56:37.0
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……
  相关解决方案