创建临时表,分组查询
分组查询,创建临时表 php -- mysql
。
//创建临时表
// 分组查询
$query = mysqli_query($connection,"SELECT (@i := case when @pre=org_id then @i + 1 else 1 end ) case_id,
sys_org.*,
(@pre:=org_id)
FROM sys_org,
(SELECT @i := 0, @pre:='')AS a GROUP BY org_id, value, id order by org_id");
$json = '';
while ($row = mysqli_fetch_assoc($query)) {
$json .=json_encode($row,JSON_UNESCAPED_UNICODE).',';
}
$json = substr($json,0,-1);
echo '['.$json.']';