update data_infant di
join (
SELECT
count(0) as high_risk_0to3_total
, CURRENT_DATE create_date
from infant i
where
year(i.birthday) = year(current_date) and i.is_highrisk = 1 and i.status in (0,2)
) as temp
on temp.create_date = di.create_date
set
di.high_risk_visit_once_rate_0to3 = if(temp.high_risk_0to3_total>0,100*(di.high_risk_visit_once_0to3_total + di.high_risk_visit_twice_0to3_total)/temp.high_risk_0to3_total,100),
di.high_risk_visit_twice_rate_0to3 = if(temp.high_risk_0to3_total>0,100* di.high_risk_visit_twice_0to3_total/temp.high_risk_0to3_total,100)
where di.create_date = CURRENT_DATE and di.is_static = 0 and di.street_code = '-1';
为什么set后面的两个字段执行会报错?是哪里适配有问题吗,改成select这两个字段好像又没问题,update语句里的set有什么要求吗
您好!能提供您的DDL、具体报错信息、和数据库版本吗?
通过图下过程验证,update执行时,并未报错:
create table data_infant( high_risk_visit_once_rate_0to3 int,high_risk_visit_once_0to3_total int, high_risk_visit_twice_rate_0to3 int, high_risk_visit_twice_0to3_total int, create_date datetime,is_static int ,street_code int ); create table infant( birthday datetime,is_highrisk int,status int ); update data_infant di join ( SELECT count(0) as high_risk_0to3_total, CURRENT_DATE create_date from infant i where year(i.birthday) = year(current_date) and i.is_highrisk = 1 and i.status in (0,2) ) as temp on temp.create_date = di.create_date set di.high_risk_visit_once_rate_0to3 = if(temp.high_risk_0to3_total>0,100*(di.high_risk_visit_once_0to3_total + di.high_risk_visit_twice_0to3_total)/temp.high_risk_0to3_total,100), di.high_risk_visit_twice_rate_0to3 = if(temp.high_risk_0to3_total>0,100* di.high_risk_visit_twice_0to3_total/temp.high_risk_0to3_total,100) where di.create_date = CURRENT_DATE and di.is_static = 0 and di.street_code = '-1';