Make zero the last in the list of ascending numbers

I am using SQLite in an android application.
In all my tables, I have a default row with index 0, which contains the default values ​​for this table.
In most cases, the default number for each field is 0, and this is the best number to use.
However, when I sort my data using the ORDER BY statement, I want all my null-value fields to be placed at the end of the list, because they are usually empty and use the default information.
The exclusion of these fields in the where statement is unacceptable, as I am trying to sort the information, not filter it.

Here is what I still have:

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

But I want:

"item 3",  1275350400
"item 42", 1275472800
"item 12", 1275476400
.
.
.
"item 1", 0
"item 2", 0
"item 4", 0
+3
5

CASE, :

 ORDER BY epoch_date.epoch == 0, epoch_date.epoch
+10

:

ORDER BY
    CASE epoch_date.epoch WHEN 0 THEN 1 ELSE 0 END,
    epoch_date.epoch

SQLite, , , , SQLite.

+4

, SQLite case "order by", - :

order by case epoch_date.epoch when 0 then 999999 else epoch_date.epoch end
0

, ?

select (...)epoch_date.epoch, case epoch_date.epoch when 0 then 1 else 0 as default
(...)
order by default,epoch_date.epoch
0

(epoch_date.epoch, 0, null, epoch_date.epoch)

- ... . , sqlite.. case.

0

Source: https://habr.com/ru/post/1754314/


All Articles