php – MySQL按特定顺序按字段排序

前端之家收集整理的这篇文章主要介绍了php – MySQL按特定顺序按字段排序前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在 PHP中运行SQL查询并按一个列排序,但按特定顺序排序

我试过这个:

$sql3="SELECT * from extension
where client_id = '".$result2["id"]."' 
ORDER BY FIELD(type,'term','queue','ivr','voicecentre','conference','callback','intercom','queuecentre') ";

但它根本就没有订购

试试这个.希望充分利用你.

select a.col as type,coalesce (COUNT,0) as count
from
(select ‘A’ as col union all
select ‘B’ as col union all
select ‘C’ as col union all
select ‘D’ as col )a
left join Table1 T
on a.col=T.type
order by FIELD(a.col,’A’,’B’,’C’,’D’) ;

Order by FIELD in MYSQL

SQL DEMO LINK

原文链接:https://www.f2er.com/php/136156.html

猜你在找的PHP相关文章