gpt4 book ai didi

MySql 首先按特定字段值排序不起作用

转载 作者:行者123 更新时间:2023-11-29 12:42:56 24 4
gpt4 key购买 nike

您好,我有一个新闻页面,我想在顶部显示用户的城市新闻。例如,这些是按时间降序排列的新闻。

+----------+-----------+-----------------------+
| CityCode | entrytime | newsheader |
+----------+-----------+-----------------------+
| 11 | 3800 | great opening |
| 10 | 3700 | flood alert |
| 12 | 3600 | new mall |
| 13 | 3500 | pollution at the city |
| 13 | 3400 | new mayor |
| 12 | 3300 | house fire |
| 11 | 3200 | traffic accident |
| 10 | 3000 | Festival at city |
+----------+-----------+-----------------------+

我住在城市 12。我想在顶部看到 CityCode=12,然后是类似的其他新闻。

+----------+-----------+-----------------------+
| CityCode | entrytime | newsheader |
+----------+-----------+-----------------------+
| 12 | 3600 | new mall |
| 12 | 3300 | house fire |
| 11 | 3800 | great opening |
| 10 | 3700 | flood alert |
| 13 | 3500 | pollution at the city |
| 13 | 3400 | new mayor |
| 11 | 3200 | traffic accident |
| 10 | 3000 | Festival at city |
+----------+-----------+-----------------------+

我试过了

Select * from news order by FIELD(CityCode,12),entrytime desc

Select * from news order by CityCode=12,entrytime desc 

这些代码不起作用。我用的是mysql 5.5我怎样才能解决这个问题?谢谢

最佳答案

试试这个:在 FIELD(CityCode,12) 的 order by 子句中添加 desc

Select * from news order by FIELD(CityCode,12) desc,entrytime desc

检查FIELD函数对ORDER BY的限制

Order BY using FIELD function

关于MySql 首先按特定字段值排序不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25863919/

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