我有以下表結構:
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'
但如果我想進入新的一年,命令不回傳任何值
SELECT * FROM table WHERE `date` >= '13.12.2021' and `date` <= '04.01.2022'
有誰知道我必須如何修改命令才能使其正常作業?
uj5u.com熱心網友回復:
因為您以錯誤的格式存盤日期,所以您應該在 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 沙箱在這里
但更好的方法是 - 以正確的格式存盤日期 YYYY-MM-DD
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/403607.html
標籤:
下一篇:Django資料庫關系
