3

这是我以逗号分隔的表格:

date, number
2010-09-02, 2
2010-10-01, 3
2011-01-01, 4
2011-02-01, 5
2011-03-01, 6
2011-05-05, 7

SQLite 的语法中似乎没有“季度”日期时间函数,所以我想知道是否有解决方法。

4

4 回答 4

6
(cast(strftime('%m', date) as integer) + 2) / 3 as quarter
于 2013-02-15T15:30:57.437 回答
4
CASE 
  WHEN cast(strftime('%m', date) as integer) BETWEEN 1 AND 3 THEN 1
  WHEN cast(strftime('%m', date) as integer) BETWEEN 4 and 6 THEN 2
  WHEN cast(strftime('%m', date) as integer) BETWEEN 7 and 9 THEN 3
  ELSE 4 END as Quarter
于 2012-06-25T22:09:33.823 回答
1

对不起,举个例子。

select month, (((3-(month%3))%3)+month)/3 as 'qtr' from months

会给我们:

1   1
2   1
3   1
4   2
5   2
6   2
7   3
8   3
9   3
10  4
11  4
12  4
于 2016-05-11T09:17:28.493 回答
-1

如何使用一些模数来解决它。

(((3-(month%3))%3)+month)/3

其中月份是 1-12 之间的一列数字

基本上我只是将事情四舍五入到最接近的 3,然后将其潜水 3。

于 2016-05-11T09:15:08.033 回答