[英]Run a sql query over a date range and group by day
我有一个具体的查询:
DECLARE
--TYPE date_array IS TABLE of DATE Index BY PLS_INTEGER;
endDate Date := SYSDATE;
startDate Date := endDate - 5;
BEGIN
Select
count(*) as Manual
from
document D,
Export_Document ED ,
Archive_Location AL
where
scan_type_nm = 'wonky'
and
D.document_id = ed.document_id
and
ed.export_document_id = Al.export_document_id
and
ed.record_create_user_id != 'Sporky'
and
Al.Archive_Location_NM IS NOT NULL
and
D.record_create_gmts >= startDate
and
D.record_create_gmts < endDate
group by D.record_create_gmts;
--Not Auto-Archived
Select
D.record_create_gmts,
count(*) As "Auto indexed"
from
document D,
Export_Document ED ,
Archive_Location AL
where
scan_type_nm = 'huh'
and
D.document_id = ed.document_id
and
ed.export_document_id = Al.export_document_id
and
ed.record_create_user_id = 'what'
and
Al.Archive_Location_NM IS NOT NULL
and
D.record_create_gmts >= startDate
and
D.record_create_gmts < endDate
group by D.record_create_gmts;
--Total indexed
Select
D.record_create_gmts,
count(*) As "Total Indexed"
from
document D,
Export_Document ED ,
Archive_Location AL
where
scan_type_nm = 'huh'
and
D.document_id = ed.document_id
and
ed.export_document_id = Al.export_document_id
and
Al.Archive_Location_NM IS NOT NULL
and
D.record_create_gmts >= startDate
and
D.record_create_gmts < endDate
Group by D.record_create_gmts;
--Total
Select
D.record_create_gmts,
count(*) as Universe
from
document D
--Export_Document ED ,
--Archive_Location AL
where
scan_type_nm = 'huh'
/* and
D.document_id = ed.document_id
and
ed.export_document_id = Al.export_document_id
and
ed.record_create_user_id != 'whawt'
and
Al.Archive_Location_NM IS NOT NULL
*/
and
D.record_create_gmts >= startDate
and
D.record_create_gmts < endDate
group by D.record_create_gmts;
END;
对于不同的情况,基本上运行相同的查询。 我正在尝试找出一种将其转换为可以在一段时间内运行并按日期分组的格式的方法。 我不是PL SQL专家,所以遇到了一些麻烦。 有任何想法吗?
您正在寻找的基本内容应该是
SELECT COUNT(*)
FROM table t
GROUP BY DATE(created_at)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.