最近遇到一个问题,

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);

 

相关文章:

  • 2021-05-30
  • 2022-12-23
  • 2021-08-16
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2023-02-22
  • 2021-08-08
猜你喜欢
  • 2021-12-07
  • 2021-11-13
  • 2022-12-23
  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案