我有两张桌子
reg_data `('date','session','anem_reading')
`velocity `('date', 'run','velocity')
我写日期插入数据时的查询,例如当date =今天,session = morning,今天anem_reading select和昨天anem_reading select where session ='morning'并按照yeasterday值减去今天的值并插入到速度表中昨天日期作为减去值的运行。该值除以24作为速度表插入速度表。 这是我的查询,它运作良好
`insert into velocity (date,run,velocity)
select DATE_SUB(CURDATE(),INTERVAL 1 DAY),((select anem_reading from reg_data where date=CURDATE() and session='morning')-(select anem_reading from reg_data where date=DATE_SUB(CURDATE(),INTERVAL 1 DAY) and session='morning')) as run ,round((((select anem_reading from reg_data where date=CURDATE() and session='morning')- (select anem_reading from reg_data where date= DATE_SUB(CURDATE(),INTERVAL 1 DAY) and session='morning')) /24 ),1) as velocity from reg_data where session='morning' and date=CURDATE();`
我想将该查询运行到以前的数据,我将其更改为
`insert into velocity (date,run,velocity) select DATE_SUB(date,INTERVAL 1 DAY),((select anem_reading from reg_data where date=date and session='morning')-(select anem_reading from reg_data where date=DATE_SUB(date,INTERVAL 1 DAY) and session='morning')) as run ,round((((select anem_reading from reg_data where date=date and session='morning')-(select anem_reading from reg_data where date= DATE_SUB(date,INTERVAL 1 DAY) and session='morning')) /24 ),1) as velocity from reg_data where session='morning' and date=date;`
但错误显示“子查询返回多个原始”我怎么能特别改变它我认为“where date = date”中的问题。