gpt4 book ai didi

php - 如何在 Codeigniter 中对始终位于顶部的特定/某些行的表进行排序?

转载 作者:行者123 更新时间:2023-11-28 23:26:31 25 4
gpt4 key购买 nike

如何使用事件记录在 Codeigniter 中对此查询进行编码?

"SELECT * FROM `my_table` ORDER BY clm_name != 2 ASC"

enter image description here

最佳答案

如果你想把pic_id = 2始终位于顶部 并且对于 ascending/descending 的其余部分更喜欢自然顺序 ( pic_id )然后按照下面给出的查询:

SELECT * 
FROM pictures
ORDER BY (pic_id <> 2) , pic_id ASC;

如果你想把pic_id (2)底部 然后:

SELECT * 
FROM pictures
ORDER BY (pic_id = 2) , pic_id ASC;

注意:

MySQL bool 表达式解析为 0/1 .所以对于 pic_id 2 (pic_id <> 2) returns 0那么顺序看起来像 ORDER BY 0, <pic_id>顺序看起来像ORDER BY 1, <pic_id>对于 2 以外的其余图片 ID .

关于php - 如何在 Codeigniter 中对始终位于顶部的特定/某些行的表进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39128873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com