问题
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