什么是Sqlite SQL语句只能查找今天的记录?(What is the Sqlite SQL statement to find todays records only?)

编程入门 行业动态 更新时间:2024-10-10 02:23:47
什么是Sqlite SQL语句只能查找今天的记录?(What is the Sqlite SQL statement to find todays records only?)

让我们说我有一张桌子上有人的名字和他们的生日(日期和时间)。 我希望能够使用以下SQL for SQLite找到今天的人们的生日(日期和时间)。

SELECT * FROM Btable WHERE Bday = date('yyyy-MM-dd')

但是,它始终使用nil数据集返回。 我还需要包括时间吗?

我的SQL语句究竟出了什么问题? 如果是这样,查询今天日期的正确SQL语句是什么。

更新:

这是我使用BETWEEN逻辑的实际SQL语句:

SELECT * FROM Alarms WHERE ALARMSTATE IN (0,1,2) AND ALARMPRIORITY IN (0,1,2,3,4) AND ALARMGROUP IN (0,1,2,3,4,5,6,7) AND ALARMTIME BETWEEN date(2012-08-02) AND date(2012-08-3) ORDER BY ALARMTIME DESC

Lets just say I have a table with people's name and their birthday (date and time). I want to be able to find people's birthday (date and time) for today using the following SQL for SQLite.

SELECT * FROM Btable WHERE Bday = date('yyyy-MM-dd')

However, it is always returning with nil dataset. Do I need to also include the time as well?

What is exactly wrong with my SQL statement? If so, what is the correct SQL statement for querying for todays date.

UPDATE:

Here is my actual SQL statement using BETWEEN logic:

SELECT * FROM Alarms WHERE ALARMSTATE IN (0,1,2) AND ALARMPRIORITY IN (0,1,2,3,4) AND ALARMGROUP IN (0,1,2,3,4,5,6,7) AND ALARMTIME BETWEEN date(2012-08-02) AND date(2012-08-3) ORDER BY ALARMTIME DESC

最满意答案

我没有旋转的实例,但这应该工作。

SELECT * FROM Btable WHERE Bday >= julianday(date('now')));

这应该像这样返回一个String:

2012-08-02 00:00:00

查询错误的地方在于它可能缺少毫秒或其他一些总是评估为false的精度。

Here is my answer.

Since my column ALARMTIME is TEXT, I am able to query my table with the following SQL statement and retrieve dataset I am looking for.

SELECT * FROM Alarms WHERE ALARMSTATE IN (0,1,2) AND ALARMPRIORITY IN (0,1,2,3,4) AND ALARMGROUP IN (0,1,2,3,4,5,6,7) AND ALARMTIME LIKE "2012/08/01%" ORDER BY ALARMTIME DESC

I simply can't convert my ALARMTIME text into datetime type.

更多推荐

本文发布于:2023-08-02 09:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1372770.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   SQL   Sqlite   statement   records

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!