代码1
$data=db('table as tb1')
->join("table2 tb2","condition")
->where($where)
->field(" tb1.xx_sum , count(tb2.id) as tb2_num ")
->select();
#原生语句类似
select tb1.xx_sum , count(tb2.id) as tb2_num
join table2 as tb2 on ...
where ...
现在遇到个问题 我这个操作里面我要wheretb2_num
这个别名
类似这样where tb1.xx_sum/tb2_num > 0.54
最终语句写成
代码2
select * from
(
select tb1.xx_sum , count(tb2.id) as tb2_num
join table2 as tb2 on ...
where ...
) as t
where tb1.xx_sum/tb2_num > 0.54
请问代码1在执行select 之前 我能获得语句 比如的到$sql
然后再
代码3
select * from
(
{$sql}
)
where tb1.xx_sum/tb2_num > 0.54
试问有这样的方法吗
直接原生sql 命名空间导入thinkphp5的数据库Db类,然后Db::query(sql);即可