mysql选择表下拉列表按组排序

时间:2017-06-02 09:12:54

标签: php mysql

我想按列表分组和按组显示顺序 我该怎么办?

enter image description here

我想这样看

enter image description here

SELECT *
FROM mytable
where num='1'
group by num (select serial From my table order by serial ASC )

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您希望num按升序排列,并且在serial内按降序排列,那么此查询将适用于您:

SELECT * from mytable
ORDER BY num, serial DESC

Working Fiddle

修改

使用Group_Concat()函数可以连接serial值:

SELECT num, name, prud, 
GROUP_CONCAT(serial ORDER BY serial DESC separator "\r\n")as GROUPED 
FROM a
GROUP BY num

Second working Fiddle

您可能需要调整separator才能让您的值在新行上打印。例如,您可以选择使用'\n'"<br>"

This questionthis question可以帮助您解决此问题。