我正在尝试为我的项目执行android SQLite查询(替代SQL查询)。当我执行替代查询时,生成了一个错误。我该如何解决这个问题?任何帮助都将不胜感激。
表格结构
TABLE (
id VARCHAR(250) NULL
,lastUpdateDate VARCHAR(500) NULL
,createdTime VARCHAR(500) NULL
,takenDate LONG NULL
,endDate LONG NULL
)
在选定日期(日期= 2022年11月30日)宣布
SQL查询
SELECT *, dateadd(s, convert(bigint, takenDate) / 1000, convert(datetime, '1970-1-1 00:00:00')) AS startdate,
dateadd(s, convert(bigint, endDate) / 1000, convert(datetime, '1970-1-1 00:00:00')) AS enddate FROM @Table
WHERE (
((@SelecctedDate>= dateadd(s, convert(bigint, takenDate) / 1000, convert(datetime, '1970-1-1 00:00:00')) AND takenDate != '0' )
AND (@SelecctedDate <= dateadd(s, convert(bigint, endDate) / 1000, convert(datetime, '1970-1-1 00:00:00')) AND endDate != '0'))
OR ((@SelecctedDate= dateadd(s, convert(bigint, takenDate) / 1000, convert(datetime, '1970-1-1 00:00:00')) AND takenDate != '0' )AND endDate='0')
OR (takenDate ='0' AND (@SelecctedDate = dateadd(s, convert(bigint, endDate) / 1000, convert(datetime, '1970-1-1 00:00:00')) AND endDate != '0'))
OR (takenDate ='0' AND endDate='0' AND (@SelecctedDate = dateadd(s, convert(bigint, createdTime) / 1000, convert(datetime, '1970-1-1 00:00:00')) ))
OR @SelecctedDate IS NULL
)
SQL查询的替代方法(Android SQLITE SQLite)
SELECT * FROM $table
WHERE (
(($selectedDate >= strftime('%Y-%m-%d', takenDate/1000, 'unixepoch') AND takenDate != '0')
AND ($selectedDate <= strftime('%Y-%m-%d', endDate/1000, 'unixepoch') AND endDate != '0'))
OR (($selectedDate = strftime('%Y-%m-%d', takenDate/1000, 'unixepoch') AND takenDate != '0') AND endDate='0')
OR (takenDate ='0' AND ($selectedDate = strftime('%Y-%m-%d', endDate/1000, 'unixepoch') AND endDate != '0'))
OR (takenDate ='0' AND endDate='0' ($selectedDate = strftime('%Y-%m-%d', lastUpdateDate/1000, 'unixepoch' )))
)
当我运行SQLite原始查询时,遇到了一个问题:
database.SQLiteException: near "(": syntax error: , while compiling: SELECT * FROM medication WHERE ((( 2022-11-29 >= strftime('%Y-%m-%d', takenDate/1000.0, 'unixepoch') AND takenDate != '0') AND ( 2022-11-29 <= strftime('%Y-%m-%d', endDate/1000, 'unixepoch') AND endDate != '0')) OR (( 2022-11-29 = strftime('%Y-%m-%d', takenDate/1000, 'unixepoch') AND takenDate != '0') AND endDate='0') OR (takenDate ='0' AND ( 2022-11-29 = strftime('%Y-%m-%d', endDate/1000, 'unixepoch') AND endDate != '0')) OR (takenDate ='0' AND endDate='0' ( 2022-11-29 = strftime('%Y-%m-%d', lastUpdateDate/1000, 'unixepoch'))))
1条答案
按热度按时间os8fio9y1#
OR (takenDate ='0' AND endDate='0'
后面缺少运算符,可能是AND
: