加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 13:03:43 所属栏目:PHP教程 来源:网络整理
导读:我试图在 PHP中运行SQL查询并按一个列排序,但按特定顺序排序 我试过这个: $sql3="SELECT * from extensionwhere client_id = '".$result2["id"]."' ORDER BY FIELD(type,'term','queue','ivr','voicecentre','conference','callback','intercom','queuecent
我试图在 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读