假设我有一个名为“users”的表,它有 40 行记录,每行都有字段:
id, firstname, group_id, login_count, stay_on_page_count
团体有
administrator (1), manager (2), employee (3)
是否可以创建一个查询,以这种方式对行进行排序和排序
group _id stay_on_page_count login_count
========= ================== ===========
1 100mins 100
1 90mins 90
2 100mins 100
3 100mins 100
1 80mins 80
1 70mins 70
2 90mins 90
3 90mins 90
1 60mins 60
1 50mins 50
2 80mins 80
3 80mins 80
1 40mins 40
1 30mins 30
2 70mins 70
3 70mins 70
基本上我想使用查询结果创建一个 4x4 网格视图。伪代码可能是
SELECT all FROM user table and to group the result in to cluster of 4,
while each 4 should have ORDER BY group_id ASC as first priority (1,1,2,3)
AND stay_on_page_count ORDER BY DESC as second priority,
AND login_count ORDER BY DESC as last or third priority
我不知道伪代码是否足够解释,但这是我唯一能想到的:)
如果可能的话,它会牺牲性能吗?有没有更好的方法来实现这一点?
我正在使用 Mysql 和 PHP (CakePHP 2.x)
谢谢