Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1.  
  2. SELECT
  3. *,
  4. COUNT(1) OVER() AS TOTAL_COUNT
  5. FROM
  6. (SELECT * FROM (
  7. SELECT
  8. a.aluno_cod,
  9. a.aluno_pescod,
  10. a.aluno_escolcod,
  11. b.pes_nome,
  12. b.pes_nome_afetivo,
  13. b.pes_nome_social,
  14. a.aluno_ra,
  15. b.pes_dtnasc,
  16. esc.pes_fantasia AS escol_nome
  17.  
  18. FROM edu_aluno a
  19.  
  20. INNER JOIN bas_pessoa b
  21. ON b.pes_cod = a.aluno_pescod
  22.  
  23. LEFT JOIN (
  24. SELECT
  25. max(em.matric_data) AS matric_data,
  26. em.matric_alunocod
  27. FROM edu_matricula em
  28. INNER JOIN edu_matricula_status ems
  29. ON em.matric_cod = ems.matricst_matriccod
  30. AND ems.matricst_ativo = 1
  31.  
  32. INNER JOIN edu_classe ec
  33. ON em.matric_classecod = ec.classe_cod
  34. AND ec.classe_tipo IS NULL
  35.  
  36. WHERE
  37. 1 = 1
  38.  
  39. GROUP BY
  40. em.matric_alunocod
  41. ) AS matricula
  42. ON matricula.matric_alunocod = a.aluno_cod
  43.  
  44. LEFT JOIN edu_matricula e
  45. ON a.aluno_cod = e.matric_alunocod
  46. AND matricula.matric_alunocod = e.matric_alunocod
  47. AND e.matric_data = matricula.matric_data
  48.  
  49. LEFT JOIN edu_classe ec
  50. ON e.matric_classecod = ec.classe_cod
  51. AND ec.classe_tipo IS NULL
  52.  
  53. LEFT JOIN edu_escola c
  54. ON c.escol_cod = ec.classe_escolcod
  55.  
  56. LEFT JOIN bas_pessoa esc
  57. ON esc.pes_cod = c.escol_pescod
  58. WHERE
  59. 1 = 1
  60. AND (esc.pes_cod IS NOT NULL OR (esc.pes_cod IS NULL AND matricula.matric_alunocod IS NULL))
  61. ORDER BY
  62. b.pes_nome
  63. ) as view_filter WHERE 1=1
  64. AND ALUNO_ESCOLCOD = 15) as view_pagging
  65.  
  66. LIMIT 30 OFFSET 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement