我有这个SQL查询:
SELECT * FROM teams ORDER BY team_name
这将为表中的团队提供结果,按团队名称排序。但是如何将元素移动到列表的开头呢?
我希望第一行有Manchester United
,其他团队按字母顺序排列。
答案 0 :(得分:3)
你可以做的是添加一个额外的字段IF(team_name='Machester United', 1, 2) AS team_one
,然后像这样执行你的ORDER BY:ORDER BY team_one, team_name
答案 1 :(得分:1)
拆分查询,然后与Union Query一起重新添加:
SELECT * FROM teams WHERE team_name="Manchester United"
UNION
SELECT * FROM teams WHERE team_name NOT LIKE "Manchester United" ORDER BY team_name