Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
按日期和时间排序无法使用SQLITE3和Python_Python_Sqlite - Fatal编程技术网

按日期和时间排序无法使用SQLITE3和Python

按日期和时间排序无法使用SQLITE3和Python,python,sqlite,Python,Sqlite,以下是我创建表的方式: c.execute(f"""CREATE TABLE IF NOT EXISTS 'news_list' ( stuff text, more_stuff text, date_posted date, UNIQUE(href) )""") 我在另一个函数中创建了这样的日期,并将其存储在DB中

以下是我创建表的方式:

c.execute(f"""CREATE TABLE IF NOT EXISTS 'news_list' (
                  stuff text,
                  more_stuff text,
                  date_posted date,
                  UNIQUE(href)
                  )""")
我在另一个函数中创建了这样的日期,并将其存储在DB中:

date_posted = f'{year}-{month}-{day}'
看起来像这样的“2018-04-12”

因为它不是生成的,而是从临时列表中提取的。所以它基本上是python中的一个字符串

然后我在另一个函数中使用此命令:

c.execute("""SELECT *
             FROM news_list
             ORDER BY date(date_posted) DESC""")
它完全不起作用。当我刷新数据库时,表保持不变,它也不会给出任何错误。我做错了什么


时间也是如此。

数据库不会改变数据的存储顺序,因为这样会降低维护数据库结构的效率。当数据从表中插入、更新或删除时,数据库引擎将根据需要移动数据以保持效率

相反,排序应用于
SELECT
查询生成的数据。您需要为每个查询指定排序,其中排序对您的应用程序很重要


在任何给定的
选择中使用的顺序都不会影响其他查询的顺序或存储的行顺序。

选择。。。ORDER BY
将按指定顺序返回指示行。它不会改变你的桌子,我该怎么做?我必须重新插入所有内容吗?@TheProgramman 123:为什么你认为你需要申请特定的订单?