最近遇到一个问题,
update sy_user as a inner join sy_user_charge_log as b on b.username=a.username set reconciliation =0 where root_id = 26 and time between '2016-12-05 14:59:05' and '2016-12-23 18:36:57';
sql运行无问题,可是在thinkphp里面的时候,就报错了1054:Unknown column 'a.root_id' in 'where clause'
后来看到一个文说的是因为运行的时候root_id的个数还没有查出来,导致报错
所以修改了下 sql语句,where分两次写出来,完美运行
$ch->alias('r')->join('__USER__ a on a.username=r.username')->where("root_id='$root_id'")->where("(status = '1') and (reconciliation = '0') and (time between '$start' and '$end')")->field('reconciliation')->save($map);