【发布时间】:2013-06-06 00:36:11
【问题描述】:
我有一个包含 eventdatetime 、 userid 等的表。数据每天都会插入到表中。
对于报告,我需要计算 userid , projectid 按周分组:Tue-Mon 一次一个月范围。
我需要有关按月按周对数据进行分组的帮助。我正在使用 Oracle。
select count(distinct( table1.projectid))as Projects, count(distinct( table2.userid)) as Users,??
from table1
join table 2
on table1.a= table2.a
where table1.e='1'
and table1.eventdatetime between sysdate-30 and sysdate-1
按 ?? 分组
我希望输出按周分组,例如: 周开始 2013-04-14
2013-04-21
【问题讨论】:
-
按月计算,这是否意味着第一周应该是新的一周而不是一天?还是周日总是 7 天一周的第一天?
-
您的示例 SQL 没有意义,因为您在 count() 函数中使用了未在 from / join s 中分配的表别名