sql语句问题,判断update如果为空则不更新数据

2025-03-25 01:29:18
推荐回答(3个)
回答1:

update     test_v8_busy_revisit t 
   set    (t.outbound_type,t.outbound_stat,t.outbound_count,t.user_code,t.outbound_time)=
    (
     select  '0','11','1',t1.sales_person,t1.sales_time 
       from  tbl_sp_sales_records t1
      where  t1.target_table='TBL_CUST_DATA_TABLE_0000000298'
        and  t1.sales_results = 'CALL_NOT_CONN_SENDMSG' 
        and  t1.sales_time   >= start_time
        and  t1.sales_time   <= end_time
        and  t2.field_50028161 = t.contact_id
  )
WHERE t.contact_id IN(SELECT t2.field_50028161 FROM tbl_cust_data_table_0000000298 t2)
;

 你的SQL中,select语句查询了t1,t2表,貌似两表连接,可是条件都是在t1表上,t2和t1没有关联,t2却和更新的表t有(t2.field_50028161 = t.contact_id
)这个关联,奇怪

所以只把你的SQL改了一下

回答2:

每种数据库的update都不太相同,你的数据库是啥?

回答3:

你update语句没有where条件啊,就算不为空更新的也是所有的吧?
加上where条件试试