[英]Display each row one by one from each category one by one using php mysql
i have the following table structure: basically it is grouping by agency_id. 我有以下表结构:基本上它是按agency_id分组。
id agency_id price type
1 1001 10000 A
2 1002 13000 B
3 1001 16000 C
4 1003 11000 A
5 1002 12000 C
6 1003 9000 D
7 1001 15000 A
8 1002 12000 A
i want to display it as following 我想显示如下
id agency_id price
1 1001 10000
2 1002 13000
4 1003 11000
3 1001 16000
5 1002 12000
6 1003 11000
i am using the following code, but its showing all the properties from 1 agency, then 2nd agency and so on. 我正在使用以下代码,但是它显示了来自1个代理商,然后是2nd代理商的所有属性。
ORDER BY
CASE properties.agency_id
WHEN 1001 THEN 1
WHEN 1002 THEN 2
WHEN 1003 THEN 3
END
but its not giving me the desire results. 但是它并没有给我带来渴望的结果。 any help will be apriciated 任何帮助将不胜枚举
Regards, 问候,
Use a solution like the one in Ranking by Group in MySQL to add a rank
column that increments within each group, and put that in a subquery. 使用类似MySQL中“按组排名”中的解决方案的方法,添加一个在每个组中递增的rank
列,并将其放入子查询中。 Then do: 然后做:
SELECT *
FROM (subquery) AS x
ORDER by rank, agency_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.