按字母顺序显示名字,但如果名字以a开头,则显示在结尾 [英] Displays firstname alphabetically but if firstname starts with a it displays at the end
问题描述
我想要这个输出..
O / P:
FirstName
Babalu >
Bhavesh
Chandan
Deepa
Heena
Neha
Akshata
Ashish
我尝试过:
我在mysql中尝试了这个查询。我想在mysql中使用ans请任何人帮助我。
通过ename从emp命令中选择ename;
I want this output..
O/P:
FirstName
Babalu
Bhavesh
Chandan
Deepa
Heena
Neha
Akshata
Ashish
What I have tried:
I tried this query in mysql . I want ans in mysql please can any one help me out.
select ename from emp order by ename ;
推荐答案
好吧,它会 - 这就是你告诉它要做的事情!
Well, it will - that is what you told it to do!
ORDER BY empname DESC
DESC
最后指定DESCENDING命令:Z first,A last。
如果你想要A,请删除 DESC
:
The DESC
at the end specifies DESCENDING order: Z first, A last.
If you want A first, remove the DESC
:
SELECT empname FROM emp ORDER BY emname;
这是您的自定义排序:
Here is your custom sort:
SELECT ename, 'id1' OrderKey FROM emp WHERE ename NOT LIKE 'A%'
UNION
SELECT ename, 'id2' OrderKey FROM emp WHERE ename LIKE 'A%'
ORDER BY OrderKey, ename;
为了确保维护自定义顺序,我需要在结果中添加一个字段以确保SELECT顺序是有序的正确地在我们对结果进行排序之前订购名称。
To ensure that the custom order is maintained, I needed to add a field to the results to ensure that the SELECT sequence is ordered correctly BEFORE we order the names when we sort the results.
这篇关于按字母顺序显示名字,但如果名字以a开头,则显示在结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!