Cakephp在查找器中发出请求

时间:2019-01-14 21:46:39

标签: php mysql cakephp cakephp-3.0

在findercakephp 3.5.10中帮助编写和执行此查询

之后,我需要按user_id对结果进行分组。

为了便于管理员使用,下面是表结构。

    select user_id, GRP, MIN(time) as Start, MAX(time) as End
      from (select user_id, time,
           @grp:=@grp+if(time>@prev+interval 30 minute,1,0) as GRP,
           @prev:=time
      from user_log, (select @prev:=NULL, @grp:=1) X
     order by time) A
     group by GRP

详细信息:

Data

1 个答案:

答案 0 :(得分:-3)

$conn = ConnectionManager::get('default');

$sql = 'select user_id, GRP, MIN(time) as Start, MAX(time) as End from (select user_id, time, @grp:=@grp+if(time>@prev+interval 30 minute,1,0) as GRP,@prev:=time from user_log, (select @prev:=NULL, @grp:=1) X order by time) A group by GRP';

$stmt = $conn->execute($sql);

$user = $stmt->fetchAll('assoc');