我的观点是:
CREATE VIEW `vista_global` AS SELECT TC.nombreCentro, TP.Profesores, TA.Alumnos
FROM tbl_centros TC
LEFT JOIN (
SELECT centro, COUNT( * ) Profesores
FROM tbl_profesores
GROUP BY centro
)TP ON TC.idCentro = TP.centro
LEFT JOIN (
SELECT centro, COUNT( * ) Alumnos
FROM tbl_alumnos
GROUP BY centro
)TA ON TC.idCentro = TA.centro
但这不好运。你能帮帮我吗?
答案 0 :(得分:0)
您不必使用子查询:
CREATE VIEW `vista_global` AS
SELECT TC.nombreCentro,
COUNT(TP.centro) Profesores,
COUNT(TA.centro) Alumnos
FROM tbl_centros TC
LEFT JOIN tbl_profesores TP ON TC.idCentro = TP.centro
LEFT JOIN tbl_alumnos TQ ON TC.idCentro = TA.centro
GROUP BY TC.nombreCentro