数据库为 sqlite3
表结构为 tblTask(ID int,TaskName varchar(20),ActionDate datetime)
问:sqlite 通过ActionDate 取季度 的 sql怎么写?
我这里暂时只知道几个例子:
取年份: select * from tblTask where strftime('%Y',ActionDate)='2011' --2011年
取月份: select * from tblTask where strftime('%m',ActionDate)='09'; -- 9月份
取季度?
取当月第几周?
答案如下:
select ActionDate
,round(strftime('%d',ActionDate)/7.0+ 0.495 ) as Week -- 当月第几周
,strftime('%m',ActionDate) AS Month -- 月份
,round(strftime('%m',ActionDate)/4.0 + 1) as Season --季度
,strftime('%Y',ActionDate) as Year -- 年份
from tblTask
本文介绍如何使用SQLite数据库查询特定季度的数据。通过strftime函数可以方便地获取日期字段对应的季度信息。此外,还介绍了如何查询年份、月份及当月的周数。
2983

被折叠的 条评论
为什么被折叠?



