Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. WITH attSummary AS(
  2. SELECT DISTINCT
  3. students.lastfirst,
  4. students.id,
  5. attendance.att_date
  6. FROM attendance
  7. JOIN attendance_code ON attendance_code.id = attendance.attendance_codeid
  8. JOIN students on attendance.studentid = students.id
  9. JOIN terms ON terms.schoolid = attendance.schoolid
  10. AND terms.isyearrec = 1
  11. AND sysdate between terms.firstday AND terms.lastday
  12. AND attendance.att_date BETWEEN terms.firstday AND terms.lastday
  13. WHERE attendance_code.att_code IN ('AU','TR')
  14. ), studentTotals AS(
  15. SELECT
  16. lastfirst,
  17. id,
  18. count(*) totalDays
  19. FROM attSummary
  20. GROUP BY lastfirst, id
  21. )
  22. SELECT lastfirst, id, totalDays
  23. FROM studentTotals
  24. WHERE totalDays >= 7
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement