Select 不同年份的两个日期之间的条目

Select entries between two dates with different years

我有以下 table 结构:

id val1 val2 val3 date
1   1    2    3   14.12.2021
2   2    3    5   17.12.2021
3   4    6    8   18.12.2021
.   .    .    .   .
.   .    .    .   .
.   .    .    .   .
9   3    4    5   04.01.2022

到目前为止,我使用以下命令:

SELECT * FROM table WHERE `date` >= '13.12.2021' and `date` <= '24.12.2021'

但是如果我想进入新的一年,命令returns我没有价值

SELECT * FROM table WHERE `date` >= '13.12.2021' and `date` <= '04.01.2022'

有谁知道我必须如何修改命令才能使其正常工作?

因为您以错误的格式存储日期,您应该在 where 子句中转换它:

select * 
from test
where substr(date,7)||'-'||substr(date,4,2)||'-'||substr(date,1,2) between '2021-12-13' and '2022-01-04';

SQLite sandbox here

但更好的方法是 - 以正确的格式存储日期 YYYY-MM-DD