首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-05-11 
sql问题,大虾请帮下忙,谢谢啦。。。Plan表Plan_idDoes_receive_dataReceive_data_time12Plan_detail表Plan_id

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……

热点排行