我当前第1天,上个月的第1天和最后一天,当前年度的第1天和最后一天,上一年的第1天和最后一天,输出日期格式为dd-mm-yyy,有一些SQL查询,但这些都不适用于SQLite。
WHERE Data> =(转换(varchar(10),(DateAdd(Month,DateDiff(Month,0, GetDate()),0)),105))和数据< =(CONVERT(VARCHAR(10),getdate(), 105))
WHERE Data> =(CONVERT(VARCHAR(10),DateAdd(Month,DateDiff(Month,0, GetDate()) - 1,0),105))和数据 < =(CONVERT(VARCHAR(10),DATEADD(S,-1,DATEADD(毫米, DATEDIFF(M,0,GETDATE()),0)),105))
WHERE Data> =(CONVERT(VARCHAR(10),DATEADD(yy, DATEDIFF(yy,0,getdate()),0),105))AND< =(CONVERT(VARCHAR(10), getdate(),105))
WHERE Data> = (CONVERT(VARCHAR(10),DATEADD(YY,-1,DATEADD(YY,DATEDIFF(YY,0,GETDATE()),0)),105) 和数据 < =(CONVERT(VARCHAR(10),DATEADD(DD,-1,DATEADD(YY,DATEDIFF(YY,0,GETDATE()),0)),105))
有人可以帮我把这个东西用在SQLite中吗? 现在我收到的错误如下:
android.database.sqlite.SQLiteException:没有这样的列:Month(代码 1):,同时编译:SELECT COUNT(*)FROM refuel WHERE car = 1 AND fuel_date> =(转换(varchar(10),(DateAdd(Month,DateDiff(Month,0, GetDate()),0)),105))AND fuel_date< =(CONVERT(VARCHAR(10),getdate(), 105))
答案 0 :(得分:1)
我发现自己回答了我的问题。我在SQLite中的等效查询是:
1. This month (eg. tday date 20160921)
Query result 01-09-2016: data('now','start of month')
Query result tday date: data('now')
2. Prev month (eg. tday date 20160921)
Query result 01-08-2016: data('now','start of month','-1 month')
Query result 31-08-2016: data('now','start of month','-1 day')
3. This year (eg. tday date 20160921)
Query result 01-01-2016: data('now','start of year')
Query result 31-12-2016: data('now','start of year','+1 year','-1 day')
4. Prev year (eg. tday date 20160921)
Query result 01-01-2015: data('now','start of year','-1 year')
Query result 31-12-2015: data('now','start of year','-1 day')