SQL Saved search No links: Difference between revisions
Jump to navigation
Jump to search
Created page with "These queries finds records that do not have links which might not be a data quality issue depending on the business rules in your country. They are added to V6.0 as Saved sea..." |
No edit summary |
||
| Line 17: | Line 17: | ||
accident_localid | accident_localid | ||
</pre> | </pre> | ||
'''Victims without link to Accident''' | |||
<pre> | |||
SELECT DISTINCT | |||
victim_localid | |||
FROM | |||
victim | |||
WHERE victim.victim_guid NOT IN ( | |||
SELECT DISTINCT | |||
victim.victim_guid | |||
FROM | |||
link | |||
Inner Join victim ON victim.victim_guid = link.from_guid | |||
WHERE | |||
link.to_link_type = 'Accident') | |||
ORDER BY | |||
victim_localid | |||
</pre> | |||
'''Hazards without links''' This query needs to be adopted to the business rules of the country e.g. all ''Closed'' or all ''CHA'' should have links | |||
<pre> | |||
SELECT DISTINCT | |||
hazard_localid | |||
FROM | |||
hazard | |||
Left Join link ON hazard.hazard_guid = link.from_guid | |||
WHERE | |||
link.from_guid IS NULL | |||
ORDER BY | |||
hazard_localid | |||
</pre> | |||
[[Category:NoPublic]] | [[Category:NoPublic]] | ||
[[Category:SQL Queries]] | [[Category:SQL Queries]] | ||
Revision as of 08:11, 13 February 2014
These queries finds records that do not have links which might not be a data quality issue depending on the business rules in your country. They are added to V6.0 as Saved searches with a syntax that works as Saved search
Accidents without link to Victim
SELECT DISTINCT accident_localid FROM accident WHERE accident.accident_guid NOT IN ( SELECT DISTINCT accident.accident_guid FROM link Inner Join accident ON accident.accident_guid = link.from_guid WHERE link.to_link_type = 'Victim') ORDER BY accident_localid
Victims without link to Accident
SELECT DISTINCT victim_localid FROM victim WHERE victim.victim_guid NOT IN ( SELECT DISTINCT victim.victim_guid FROM link Inner Join victim ON victim.victim_guid = link.from_guid WHERE link.to_link_type = 'Accident') ORDER BY victim_localid
Hazards without links This query needs to be adopted to the business rules of the country e.g. all Closed or all CHA should have links
SELECT DISTINCT hazard_localid FROM hazard Left Join link ON hazard.hazard_guid = link.from_guid WHERE link.from_guid IS NULL ORDER BY hazard_localid