Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH combined_tables AS (
- SELECT
- sem.codigo_semestre,
- a.codigo,
- s.cup,
- s.rot,
- t.nombre,
- 'serv' AS tabla_origen
- FROM serv s
- INNER JOIN asignatura a ON a.id = s.id_asignatura
- INNER JOIN tipo t ON t.id = s.tipo_practica
- INNER JOIN semestres sem ON sem.id = s.semestre
- WHERE
- semestre_ano = 11 AND
- s.estatus = 1 AND
- s.estado = 'aprobado'
- UNION ALL
- SELECT
- sem.codigo_semestre,
- a.codigo,
- s.cup,
- s.rot,
- t.nombre,
- 'dep' AS tabla_origen
- FROM dep s
- INNER JOIN asignatura a ON a.id = s.id_asignatura
- INNER JOIN tipo t ON t.id = s.tipo_practica
- INNER JOIN semestres sem ON sem.id = s.semestre
- WHERE
- semestre_ano = 11 AND
- s.estatus = 1 AND
- s.estado = 'aprobado'
- UNION ALL
- SELECT
- sem.codigo_semestre,
- a.codigo,
- s.cup,
- s.rot,
- t.nombre,
- 'cor' AS tabla_origen
- FROM cor s
- INNER JOIN asignatura a ON a.id = s.id_asignatura
- INNER JOIN tipo t ON t.id = s.tipo_practica
- INNER JOIN semestres sem ON sem.id = s.semestre
- WHERE
- semestre_ano = 11 AND
- s.estatus = 1 AND
- s.estado = 'aprobado'
- UNION ALL
- SELECT
- sem.codigo_semestre,
- a.codigo,
- s.cup,
- s.rot,
- t.nombre,
- 'edu' AS tabla_origen
- FROM edu s
- INNER JOIN asignatura a ON a.id = s.id_asignatura
- INNER JOIN tipo t ON t.id = s.tipo_practica
- INNER JOIN semestres sem ON sem.id = s.semestre
- WHERE
- semestre_ano = 11 AND
- s.estatus = 1 AND
- s.estado = 'aprobado'
- )
- SELECT
- codigo_semestre,
- codigo,
- cup,
- rot,
- nombre,
- tabla_origen
- FROM combined_tables;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement