如何在 SQLite3 中按字母顺序显示元素
问题描述:
我想使用 SQLite3 语句按字母顺序显示我的记录:
I want to display my records in alphabetically order using SQLite3 statement:
SELECT * FROM Medicine ORDER BY name ASC
但是……
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
答
您可以在 ORDER BY
中使用 COLLATE NOCASE
子句,以便排序不区分大小写:>
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 |