[英]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.