使零出现在升序数字列表的最后 [英] make zero appear last in a list of ascending numbers
问题描述
我在 Android 应用程序中使用 SQLite.
在我的所有表中,我都有一个索引为 0 的默认行,用于保存该表的默认值.
在大多数情况下,每个字段的默认数字为 0,这是最适合使用的数字.
但是,当我使用 ORDER BY 语句对数据进行排序时,我希望将所有零值字段放在列表的末尾,因为它们通常为空并使用默认信息.
在 where 语句中排除这些字段是不可接受的,因为我正在尝试对信息进行排序,而不是对其进行过滤.
I'm using SQLite in an Android application.
In all of my tables I have a default row with an index of 0 that holds default values for that table.
In most situations the default number for each field is 0 and that is the best number to use.
However, when I sort my data using an ORDER BY statement I want to have all of my zero value fields put at the end of the list as they're generally empty and using default information.
Excluding these fields in a where statement is unacceptable as I'm trying to sort information, not filter it.
这是我目前所拥有的:
select distinct item.name, epoch_date.epoch
from epoch_date, time
where (time.begin_date_id = epoch_date._id)
and (item.time_id = time._id)
order by epoch_date.epoch;
在我的沙箱数据库中,这会返回如下内容:
In my sandbox database, this returns something like:
"item 1", 0
"item 2", 0
"item 4", 0
.
.
.
"item 3", 1275350400
"item 42", 1275472800
"item 12", 1275472800
但我想要的是:
"item 3", 1275350400
"item 42", 1275472800
"item 12", 1275476400
.
.
.
"item 1", 0
"item 2", 0
"item 4", 0
推荐答案
等同于 CASE
语句建议,但更短:
Equivalent to the CASE
statement suggestion, but shorter:
ORDER BY epoch_date.epoch == 0, epoch_date.epoch
这篇关于使零出现在升序数字列表的最后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!