不确定这是否可能。我正在尝试让一个mysqli查询工作,它将结果分组在一起,然后在每个组中随机显示结果。这是我当前的代码,它只是以随机顺序生成所有结果。
select * from swt_counties_members
where
county_id=".$sCounty[1]."
AND
status=1
OR
county_id=0
AND
status=1
order by rand()
我需要它做的是按service_id分组,然后随机显示每个组中的记录。像这样的
select * from swt_counties_members
where
county_id=".$sCounty[1]."
AND
status=1
OR
county_id=0
AND
status=1
group by service_id
order by rand()
其中它将首先根据service_id对所有结果进行分组,然后在每个分组中随机显示中的结果
希望有意义:)非常感谢
您想要ORDER BY,而不是GROUP BY
select * from swt_counties_members where county_id=".$sCounty[1]." AND status=1 OR county_id=0 AND status=1 order by service_id,rand()