简体   繁体   English

SQL select语句,将派生表与JasperReports一起使用,将在几周内恢复我的数据

[英]Sql select statement that will bring back my data in weeks, using derived tables with JasperReports

I'm currently running the following sql statement in JasperReports Server to bring back my data using derived tables. 我当前正在JasperReports Server中运行以下sql语句,以使用派生表恢复数据。

Select count(createddate) as ModulesCreatedDuringPastWeek, 
count(updateddate) as  ModulesUpdatedDuringPastWeek, 
createddate, 
updateddate 
from merchendisingmodule 
group by merchendisingmodule.createddate, merchendisingmodule.updateddate

However when grouping my data, I am only able to do it in Year, quarter, month and day. 但是,对数据进行分组时,只能在年,季度,月和日进行。 However for my report I'm needing the data to be group weeks, and so I was wondering what I will need to add to my code to do this. 但是对于我的报告,我需要将数据设为小组周,因此我想知道要添加到代码中需要执行哪些操作。

DATEADD(D,-DATEPART(weekday,createddate)+1,createddate)

I use this method to prevent issues around the year transitions (week 53 in first days of januari and also in the last days of december, will group days together that are 360 days apart). 我使用这种方法来防止在一年中的过渡问题(在januari的第一天和12月的最后几天中的第53周,将相隔360天的天分组在一起)。 I use the first day of the week, instead of week numbers. 我使用一周的第一天,而不是星期几。 I can use these dates to group by. 我可以使用这些日期进行分组。 Also this will ensure that every week is 7 days long, instead of the last week of the year being only 3 or 4 days long. 而且,这将确保每个星期有7天,而不是一年的最后一周只有3或4天。

Btw, in this example the first day of the week is sunday. 顺便说一句,在此示例中,一周的第一天是星期日。

If your dates include time, use: 如果您的日期包含时间,请使用:

CAST(FLOOR(CAST(createddate AS FLOAT)) AS DATETIME)

instead of createddate in the above SYNTAX 而不是上面的SYNTAX中的createddate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM