tp 子查询 sql 或框架查询方法
小白
2020-09-04
【原创文章】
tp 子查询 sql 或框架查询方法
tp 子查询 sql 或框架查询方法
$ss = 'select ObservTime,StationID from tc_autostation where StationID=\'TC001\' order by ObservTime desc limit 10'; $sql = 'select * from (select ObservTime,StationID from tc_autostation where StationID=\'TC001\' order by ObservTime desc limit 10) as tems where ObservTime=\'2019-12-11 10:00:00\''; $ifno = Db::query($sql); // return json(['where'=>$where,'or'=>$whereor]); $subQuery = Db::table('tc_autostation') ->field('StationID,RH,TT,ObservTime,status,InsertTime') ->where($where) ->buildSql(); $subQuery2 = Db::table($subQuery . ' a') // ->where('a.ObservTime', '=', '2019-12-11 10:00:00') ->order('ObservTime', 'desc') ->limit($curr*$nums,$nums) ->buildSql(); $info = Db::table($subQuery2 . ' c') // ->where('a.ObservTime', '=', '2019-12-11 10:00:00') ->order('ObservTime', 'desc') ->limit($curr*$nums,$nums) ->select();