我一直在尝试在 dhis2 中找到存储上传汇总报告的时间戳的表。我需要该数据用于我正在使用 SQL 视图创建的报告。我设法找到一个名为 datavalueaudit 的表,它有一个时间戳列,但我尝试的每个查询都会提取构成聚合报告的数据元素的时间戳。我仍然是 sql 和 dhis2 的新手,所以我不知道如何解决这个问题。我正在尝试修改我有点理解但仍然觉得有点复杂的查询
以下是原始查询
SELECT DISTINCT p.startdate, prov.name AS Province, par.name AS cheifdom, ou.name AS village, regexp_replace(ou.phonenumber, '+260', '0'), CASE WHEN b.reported IS NULL THEN 0: :integer ELSE 1::integer END AS 报告自 datasetsource dss CROSS JOIN (SELECT DISTINCT periodid, startdate FROM period WHERE startdate <= now() AND periodtypeid = (SELECT periodtypeid FROM periodtype WHERE name ='Monthly') ORDER BY startdate DESC OFFSET 1 限制 12) p LEFT JOIN (SELECT DISTINCT dv.sourceid, dv.periodid, TRUE AS reports from datavalue dv INNER JOIN (SELECT DISTINCT periodid, startdate FROM period WHERE startdate <= now() AND periodtypeid = (SELECT periodtypeid FROM periodtype WHERE name ='Monthly') ORDER BY startdate DESC OFFSET 1 LIMIT 12) a ON dv.periodid = a.periodid WHERE dv.dataelementid IN (SELECT DISTINCT dataelementid FROM datasetmembers WHERE datasetid = (SELECT datasetid FROM dataset WHERE uid = 'Hbcr2fLc9jM'))) b ON b.sourceid = dss.sourceid AND b.periodid = p.periodid INNER JOIN organizationunit ou ON dss.sourceid = ou.organisationunitid INNER JOIN organizationunit par ON ou.parentid = par.organisationunitid INNER JOIN organizationunit prov ON par.parentid = prov.organisationunitid INNER JOIN _periodstructure ps ON p.periodid = ps.periodid WHERE dss.datasetid = (SELECT datasetid FROM dataset WHERE uid = 'Hbcr2fLc9jM') ORDER BY prov.name, par.name, ou.name, p.startdateorganizationunitid INNER JOIN organizationunit par ON ou.parentid = par.organisationunitid INNER JOIN organizationunit prov ON par.parentid = prov.organisationunitid INNER JOIN _periodstructure ps ON p.periodid = ps.periodid WHERE dss.datasetid = (SELECT datasetid FROM dataset WHERE uid = 'Hbcr2fLc9jM') 按 prov.name、par.name、ou.name、p.startdate 排序organizationunitid INNER JOIN organizationunit par ON ou.parentid = par.organisationunitid INNER JOIN organizationunit prov ON par.parentid = prov.organisationunitid INNER JOIN _periodstructure ps ON p.periodid = ps.periodid WHERE dss.datasetid = (SELECT datasetid FROM dataset WHERE uid = 'Hbcr2fLc9jM') 按 prov.name、par.name、ou.name、p.startdate 排序
以下是我尝试修改的
SELECT DISTINCT p.startdate, prov.name AS Province, par.name AS cheifdom, ou.name AS village, regexp_replace(ou.phonenumber, '+260', '0'), CASE WHEN b.reported IS NULL THEN 0: :integer ELSE 1::integer END AS 报告,dva.timestamp AS “按时报告”来自 datasetsource dss CROSS JOIN (SELECT DISTINCT periodid, startdate FROM period WHERE startdate <= now() AND periodtypeid = (SELECT periodtypeid FROM periodtype WHERE name ='Monthly') ORDER BY startdate DESC OFFSET 1 LIMIT 12) p LEFT JOIN (SELECT DISTINCT dv.sourceid, dv.periodid, TRUE AS reports from datavalue dv INNER JOIN (SELECT DISTINCT periodid, startdate FROM period WHERE startdate <= now( ) AND periodtypeid = (SELECT periodtypeid FROM periodtype WHERE name ='Monthly') ORDER BY startdate DESC OFFSET 1 LIMIT 12) a ON dv.periodid = a.periodid WHERE dv.dataelementid IN (SELECT DISTINCT dataelementid FROM datasetmembers WHERE datasetid = (SELECT datasetid FROM dataset WHERE uid = 'Hbcr2fLc9jM'))) b ON b.sourceid = dss.sourceid AND b.periodid = p.periodid LEFT JOIN (SELECT DISTINCT dv.timestamp, dv.periodid, TRUE AS 从 datavalueaudit dv INNER JOIN (SELECT DISTINCT periodid, startdate FROM period WHERE startdate <= now() AND periodtypeid = (SELECT periodtypeid FROM periodtype WHERE name ='Monthly') ORDER BY startdate DESC OFFSET 1 LIMIT 12) a ON dv.periodid = a.periodid WHERE dv.dataelementid IN (SELECT DISTINCT MAX(dataelementid) FROM datasetmembers WHERE datasetid = '29827' GROUP BY datasetid)) k ON k.periodid = p.periodid INNER加入组织单位 ou ON dss.sourceid = ou.organisationunitid 左加入 datavalueaudit dv ON dss.sourceid = dv。organizationunitid INNER JOIN datavalueaudit dva ON k.timestamp = dva.timestamp INNER JOIN organizationunit par ON ou.parentid = par.organisationunitid INNER JOIN organizationunit prov ON par.parentid = prov.organisationunitid INNER JOIN _periodstructure ps ON p.periodid = ps.periodid WHERE dss.datasetid = (SELECT datasetid FROM dataset WHERE uid = 'Hbcr2fLc9jM') ORDER BY prov.name, par.name, ou.name, p.startdate, dva.timestamp开始日期,dva.timestamp开始日期,dva.timestamp
我尝试修改的查询仅提取已上传完成聚合报告的数据集中所有数据元素的时间戳,而不是仅上传已完成聚合报告的时间戳
我想添加一个新列,该列从存储它的表中提取时间戳数据,但仅适用于上传完成的汇总报告*(记录)时。