我一直在尝试在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&#39 ;),例如b.reported IS NULL THEN 0 :: integer ELSE 1 :: integer END AS报告FROM 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 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.s ourceid AND b.periodid = p.periodid INNER JOIN organisationunit ou ON dss.sourceid = ou.organisationunitid INNER JOIN organisationunit par ON ou.parentid = par.organisationunitid INNER JOIN organisationunit 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
以下是我尝试修改的内容
SELECT DISTINCT p.startdate,prov.name AS province,par.name AS cheifdom,ou.name AS village,regexp_replace(ou.phonenumber,' + 260',' 0&#39 ;),例如b.reported IS NULL THEN 0 :: integer ELSE 1 :: integer END AS报告,dva.timestamp AS"报告时间" FROM 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报告FROM datavalue dv INNER JOIN(SELECT DISTINCT periodid,startdate FROM period WHERE startdate< = now()AND periodtypeid =(SELECT periodtypeid FROM periodtype WHERE name =& #39;每月')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 =&# 39; Hbcr2fLc9jM')))b ON b.sourceid = dss.sourceid AND b.periodid = p.periodid LEFT JOIN(SELECT DISTINCT dv.timestamp,dv.periodid,TRUE AS from 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 JOIN organisationunit ou ON dss.sourceid = ou.organisationunitid LEFT JOIN datavalueaudit dv ON dss.sourceid = dv.organisationunitid INNER JOIN datavalueaudit dva ON k.timestamp = dva.timestamp INNER JOIN organisationunit par ON ou.parentid = par.organisationunitid INNER JOIN organisationunit prov ON par.parentid = prov.organisationunitid INNER JOIN _periodstructure ps ON p.periodid = ps.periodid WHERE dss.datasetid =(SELECT datasetid FROM dataset WHERE uid =& #39; Hbcr2fLc9jM')ORDER BY prov.name,par.name,ou.name,p.startdate,dva.timestamp
我尝试修改的查询仅提取上传完成的汇总报表的数据集中的所有数据元素的时间戳,而不是上传完成的汇总报表时的时间戳
我想添加一个新列,从存储它的表中提取时间戳数据,但仅限于已上载完成的聚合报告*(记录)的时间。
答案 0 :(得分:0)
DHIS 2中没有关于汇总报告的直接概念。查看 datavalue 表的创建的列将为您提供近似值。如果您的数据上传客户端使用数据值集并将已完成的属性设置为 true ,则有效地创建完整数据集注册,您可以在 completedatasetregistration 表中查询记录。