Sqlite Order by Date1530019888000

SQLite Order By Date1530019888000

you can do it like this

SELECT * FROM Table ORDER BY date(dateColumn) DESC Limit 1

Sqlite order by date (yyyy/mm/dd format)

When stored in (dd/mm/yy) it will not be able to differentiate in minutes/hours. Is there no sorting occurring at all? Can you show us some sample data and output?

I've had this issue before, and I had to add in actual time rather that only date.

If that is the issue, the following link will help:
SQLite Order By Date

It's basically what you have, but you need to create your column with DATETIME and need to insert with the following format:

'2007-01-01 10:00:00'

If not, then please post the additional data and I will try to help.

SQLite, Sorting a data base by a timestamp

Change the limit to the number of rows you want:

SELECT * FROM Table ORDER BY dateColumn DESC Limit 10000000;

you can figure out how many rows you have using

SELECT count(*) FROM Table;

and give a limit greater than that number. Beware: If you want all rows you should really put a limit, because if you don't put a limit and simply do

SELECT * FROM Table ORDER BY dateColumn DESC;

it will limit the output to a certain number depending on your system configurations so you might not get all rows.

SQLite sorting order by asc

try this query:

SELECT date(substr(`date_column`,7,4)||'-'||substr(`date_column`,4,2)||'-'||substr(`date_column`,1,2)) as text_date FROM `table` order by text_date asc

sqlite order by string containing number with comma delimiter

If the commas are used consistently, you can use:

order by length(cases), cases

Otherwise, you can remove the commas and convert:

order by cast(replace(cases, ',', '') as int)

Have an issue when ORDER BY Date DESC

Warning: The SQLite query you are about to see is ugly and should not be repeated at home, unless you totally messed up your date format, in which case you might have no other choice.

We can try doing an ORDER BY which builds out the correct two digit month and day for each date. Note that in the case of your data, this necessitates padding single digit months and days with zero.

SELECT *
FROM contacts
ORDER BY
SUBSTR(Date, 1, 4) DESC,
CASE WHEN INSTR(SUBSTR(Date, 6), '/') = 2
THEN '0' || SUBSTR(Date, 6, 1)
ELSE SUBSTR(Date, 6, 2) END DESC,
CASE WHEN LENGTH(SUBSTR(SUBSTR(Date, 6), INSTR(SUBSTR(Date, 6), '/') + 1)) = 1
THEN '0' || SUBSTR(SUBSTR(Date, 6), INSTR(SUBSTR(Date, 6), '/') + 1)
ELSE SUBSTR(SUBSTR(Date, 6), INSTR(SUBSTR(Date, 6), '/') + 1) END DESC;

Note that the correct long term solution would be for you to store all months and days as two digit numbers, padding with zero on the left in the case of single digits (your years would most likely always be 4 digits).

Here is a link to a demo which demonstrates the logic of the above query. Note that I created it using MySQL, because SQLite is not supported, but other than having to replace || with CONCAT, the query is identical.

Demo

Here is the output which shows the correct order along with the year, month, and day components correctly being extracted:

Sample Image

Android Sqlite order by desc not working correctly

i want result: 2.1, 6.6, 7.5..... so on

That's an ascending order, not descending. Ascending is the default but you can also specify ORDER BY column ASC.

Id: 8 ,Score: 10.1 ,Letter: S
Id: 6 ,Score: 11.1 ,Letter: S
Id: 7 ,Score: 2.1 ,Letter: S
Id: 3 ,Score: 6.6 ,Letter: S
Id: 2 ,Score: 7.5 ,Letter: S
Id: 4 ,Score: 8.8 ,Letter: S
Id: 1 ,Score: 9.4 ,Letter: S
Id: 5 ,Score: 9.7 ,Letter: S

This is an ascending order but sorted lexicographically (alphabetically), not numerically. If you want numerical sorting, either set the gpoint column type to REAL or cast the values to REAL:

CREATE TABLE ... (... gpoint REAL ...)

or

SELECT ... ORDER BY CAST(gpoint AS REAL)


Related Topics



Leave a reply



Submit