简体   繁体   English

SQLite Python-如何按日期排序(最新的优先)

[英]Sqlite python - how to sort by date(newest first)

I have an sqlite DB that has a column called date which is a DATETIME . 我有一个sqlite数据库,其中有一个名为date的列,它是DATETIME I have used this: 我用了这个:

cur.execute("SELECT * FROM Posts ORDER BY date(date) DESC")

However, it gives me the oldest first, and I want it the other way around. 但是,它给了我最早的一个,而我反过来想要它。 I a newbie to SQL, so could someone help me out? 我是SQL的新手,所以有人可以帮助我吗?

EDIT: Just to be clear for anyone wondering, this is the correct answer: 编辑:只是想让任何想知道的人都知道,这是正确的答案:

cur.execute("SELECT * FROM Posts ORDER BY Date DESC")

Hope this helps someone! 希望这对某人有帮助!

I'll suggest you to try the inverse: 我建议您尝试相反的方法:

cur.execute("SELECT * FROM Posts ORDER BY date ASC")

and see if it works. 看看是否可行。

Hope this helps! 希望这可以帮助!

创建数据库表时,请尽量不要使用“ date”一词作为列名,因为该名称是系统保留的,请尝试将该名称从date更改为另一个名称,然后重试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM