Created
October 3, 2013 08:09
-
-
Save danielkec/6806747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT verze.IDVERZE, | |
zosoba.zranena | |
FROM DN.DN_VERZE verze | |
LEFT JOIN DN.DN_DN dn ON verze.IDDN = dn.IDDN | |
LEFT JOIN cc.cc_ndnZaznamPlatSchval dnPlat ON dn.idNdnZaznamPlatSchval = dnPlat.idNdnZaznamPlatSchval | |
LEFT JOIN cc.cc_ndnKvalUdalost dnUdalost ON verze.idNdnKvalUdalost = dnUdalost.idNdnKvalUdalost | |
LEFT JOIN ( | |
SELECT | |
osoba.idVerze, | |
--osoba | |
MAX(CASE WHEN foZraneni.KODNDNTYPZRANENI IN ('1', '3', '4') THEN 1 ELSE null END) AS zranena | |
FROM dn.dn_osoba osoba | |
LEFT JOIN dn.dn_fo fo ON osoba.idOsoba = fo.idOsoba | |
LEFT JOIN cc.cc_ndnRoleFo foRole ON fo.idNdnRoleFo = foRole.idNdnRoleFo | |
--ciselniky | |
LEFT JOIN cc.cc_ndnZaznamPlat plat ON osoba.idNdnZaznamPlat = plat.idNdnZaznamPlat | |
LEFT JOIN cc.cc_ndnTypZraneni foZraneni ON fo.idNdnTypZraneni = foZraneni.idNdnTypZraneni | |
WHERE | |
--jen platne osoby | |
plat.kodNdnZaznamPlat = '1' | |
-- zucatnena osoba | |
AND foRole.KODNDNROLEFO = '0' | |
GROUP BY osoba.idVerze | |
) zosoba ON | |
verze.idVerze = zosoba.idVerze | |
WHERE verze.VERZEDATUMCASDO > '2011-11-01-24.00.00' | |
--platna dopravni nehoda | |
AND dnPlat.kodNdnZaznamPlatSchval = '1' | |
AND dnUdalost.kodNdnKvalUdalost IN ('1', '2', '9') | |
--ma zranenou, osetrenou nebo mrtvou | |
AND zosoba.zranena = 1 | |
--uz byla exportovana | |
AND verze.IDVERZE NOT IN( | |
SELECT verzeExportDavka.IDVERZE | |
FROM OR.OR_VERZEEXPORTDAVKA verzeExportDavka | |
WHERE verzeExportDavka.idUDZSExportDavka IS NOT NULL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment