Last active
December 24, 2015 12:09
-
-
Save danielkec/6796222 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 | |
FULL JOIN OR.OR_VERZEEXPORTDAVKA verzeExportDavka ON verze.IDVERZE = verzeExportDavka.IDVERZE | |
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 verzeExportDavka.idUDZSExportDavka IS NULL | |
FETCH FIRST 100 ROWS ONLY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment