aeroson

Untitled

Sep 19th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. -- select all members of AM 2 Battalion (taw id 1330)
  2. select p.* from People p
  3. join PeopleToUnits p2u on p2u.PersonId = p.PersonId and p2u.UnitId in
  4. (
  5. select * from
  6. (select battalion.UnitId from Units battalion where battalion.TawId = '1330') a
  7. union all
  8. (select platoon.UnitId from Units battalion
  9. join Units platoon on battalion.UnitId = platoon.ParentUnit_UnitId and battalion.TawId = '1330')
  10. union all
  11. (select squad.UnitId from Units battalion
  12. join Units platoon on battalion.UnitId = platoon.ParentUnit_UnitId and battalion.TawId = '1330'
  13. join Units squad on platoon.UnitId = squad.ParentUnit_UnitId)
  14. union all
  15. (select fireteam.UnitId from Units battalion
  16. join Units platoon on battalion.UnitId = platoon.ParentUnit_UnitId and battalion.TawId = '1330'
  17. join Units squad on platoon.UnitId = squad.ParentUnit_UnitId
  18. join Units fireteam on squad.UnitId = fireteam.ParentUnit_UnitId)
  19. )
  20. group by p.PersonId
  21. order by name;
Add Comment
Please, Sign In to add comment