SQL Saved search MA quality: Difference between revisions

From IMSMA Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 37: Line 37:
hazreduc.hazreduc_localid
hazreduc.hazreduc_localid
</pre>
</pre>
 
'''Open Hazards with links to HazRed or QM'''
 
<pre>
 
SELECT DISTINCT hazard_localid
FROM hazard Inner Join imsmaenum ON hazard.status_guid = imsmaenum.imsmaenum_guid
Inner Join link ON hazard.hazard_guid = link.from_guid
WHERE imsmaenum.enumvalue =  'Active' AND (link.to_link_type =  'HAZARD_REDUCTION' OR link.to_link_type =  'QA' )
ORDER BY
hazard_localid
</pre>


[[Category:NoPublic]]
[[Category:NoPublic]]
[[Category:SQL Queries]]
[[Category:SQL Queries]]

Revision as of 09:22, 13 February 2014

These queries depends on the business rules in the country. More queries than the ones below are added to V6.0 as Saved searches with a syntax that works as Saved search
CR where area/calc area have 15% difference

SELECT 
hazreduc_localid,
areasize,
calculated_area
FROM hazreduc Inner Join imsmaenum ON hazreduc.hazreductypeenum_guid = imsmaenum.imsmaenum_guid 
WHERE imsmaenum.enumvalue =  'CompletionReport' AND 
(  (coalesce(areasize,0)  > (coalesce( hazreduc.calculated_area, 0 ) * 1.15 )) OR 
( coalesce( areasize, 0 )  < (coalesce( hazreduc.calculated_area, 0 ) * 0.85) ))
ORDER BY
hazreduc_localid

CR without devices

SELECT hazreduc.hazreduc_localid
FROM hazreduc Inner Join imsmaenum ON hazreduc.hazreductypeenum_guid = imsmaenum.imsmaenum_guid 
Left Join hazreducdeviceinfo ON hazreduc.hazreduc_guid = hazreducdeviceinfo.hazreduc_guid 
WHERE imsmaenum.enumvalue =  'CompletionReport' AND 
hazreducdeviceinfo.hazreduc_guid IS NULL
ORDER BY
hazreduc.hazreduc_localid

CR without polygon/polyline

SELECT hazreduc.hazreduc_localid
FROM hazreduc Inner Join imsmaenum ON hazreduc.hazreductypeenum_guid = imsmaenum.imsmaenum_guid 
WHERE imsmaenum.enumvalue =  'CompletionReport' AND 
( hazreduc.hasgeodata = FALSE OR hazreduc.hazreduc_guid NOT IN 
(SELECT DISTINCT hazreduc.hazreduc_guid 
FROM hazreduc Inner Join hazreduc_has_geospatialinfo ON hazreduc.hazreduc_guid = hazreduc_has_geospatialinfo.hazreduc_guid 
Inner Join geospatialinfo ON hazreduc_has_geospatialinfo.geospatialinfo_guid = geospatialinfo.geospatialinfo_guid 
Inner Join imsmaenum ON geospatialinfo.shapeenum_guid = imsmaenum.imsmaenum_guid 
WHERE imsmaenum.enumvalue  LIKE  'Poly%'))
ORDER BY
hazreduc.hazreduc_localid

Open Hazards with links to HazRed or QM

SELECT DISTINCT hazard_localid
FROM hazard Inner Join imsmaenum ON hazard.status_guid = imsmaenum.imsmaenum_guid 
Inner Join link ON hazard.hazard_guid = link.from_guid 
WHERE imsmaenum.enumvalue =  'Active' AND (link.to_link_type =  'HAZARD_REDUCTION' OR link.to_link_type =  'QA' )
ORDER BY
hazard_localid