How to display elements in alphabetically order ins SQLite3

只谈情不闲聊 提交于 2020-08-09 19:30:53

问题


I want to display my records in alphabetically order using SQLite3 statement:

SELECT * FROM medicine ORDER BY name ASC

but..

1) It display records like this for example: 
ADRENALINE 
BETALOC 
CAPTORIL
……
Adrenaline
Betaloc
Captopril
……
adrenaline
betaloc
captopril
…..
2) But I want that sqlite3 displays like this:
ADRENALINE
Adrenaline
adrenaline
………
BETALOC
Betaloc
betaloc
………
CAPTOPRIL
Captopril
captopril
………….

How to write it statement that it displays like In the second case I know that upper letter have the priority but I think it’s a way to do it


回答1:


You can use the COLLATE NOCASE clause in ORDER BY so the sorting is case insensitive:

SELECT * 
FROM medicine 
ORDER BY name COLLATE NOCASE ASC

See the demo.
Results:

| name       |
| ---------- |
| ADRENALINE |
| Adrenaline |
| adrenaline |
| BETALOC    |
| Betaloc    |
| betaloc    |
| CAPTOPRIL  |
| Captopril  |
| captopril  |


来源:https://stackoverflow.com/questions/63081330/how-to-display-elements-in-alphabetically-order-ins-sqlite3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!