开发者

Help with Create View

My View is:

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 J开发者_高级运维OIN (

SELECT centro, COUNT( * ) Alumnos
FROM tbl_alumnos
GROUP BY centro
)TA ON TC.idCentro = TA.centro

But this not run well. Do you can help me, please?


You don't have to use subqueries:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜