我希望从DB2的发布年开始,每周(也是月份)获得数据。
e.g。 select * From tableName where week=10 or week=40;
请帮助在DB2中编写SQL。
答案 0 :(得分:0)
您可以使用WEEK_ISO()
函数返回整数值1-53
select * From tableName where WEEK_ISO(yearValue)=10 or WEEK_ISO(yearValue)=40;
答案 1 :(得分:0)
我已经使用了以下SQL来明智地获取数据。谢谢你的朋友的支持。
- 每周计算数据 -
SELECT WEEK_ISO(login_datetime) AS Week, YEAR(login_datetime) AS Year
FROM TableName
WHERE login_datetime BETWEEN '2012-01-01' AND '2013-12-31'
GROUP BY WEEK_ISO(login_datetime), YEAR(login_date)
ORDER BY YEAR(login_datetime), WEEK_ISO(login_datetime)
- 按月计算数据 -
SELECT MONTH(login_datetime) AS Month, YEAR(login_datetime) AS Year
FROM TableName
WHERE login_datetime BETWEEN '2012-01-01' AND '2013-12-31'
GROUP BY MONTH(login_datetime), YEAR(login_datetime)
ORDER BY YEAR(login_datetime), MONTH(login_datetime)