如何在 SQLite3 中按字母顺序显示元素 [英] How to display elements in alphabetically order ins SQLite3

查看:51
本文介绍了如何在 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  |

这篇关于如何在 SQLite3 中按字母顺序显示元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆