gpt4 book ai didi

android - 在 SQLite 中获取最大日期

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:51:31 24 4
gpt4 key购买 nike

我使用 SQLite 作为我的 Android 应用程序的数据存储。我创建了一个包含日期时间类型列的表。当我插入记录或选择语句时,我使用 dd.MM.yyyy (10.08.2012) 格式作为日期。

现在,我无法获取具有最新/最大日期的行。我试过使用 MAX(date_column) 语句,但它返回错误的日期。我的表中有以下日期,它返回 31.07.2012 而不是 04.08.2012。有人知道我做错了什么吗?

04.08.2012
03.08.2012
02.08.2012
01.08.2012
31.07.2012
30.07.2012

部分代码如下:

String selection = "measurementDate = (SELECT MAX(measurementDate) FROM Measurements)";
Cursor cursor = database.query("Measurements", allColumns, selection, null, null, null, null);
cursor.moveToFirst();
...

最佳答案

难道是因为31?
尝试看看这是否有帮助:

SELECT measurementDate FROM Measurements ORDER BY measurementDate desc LIMIT 1

关于android - 在 SQLite 中获取最大日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11893218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com