我无法创建视图。您可以在下面找到我的代码。有人可以帮帮我吗?
CREATE VIEW V_Campeonato AS SELECT team.tim_cod_inscri_time
, SUM( CASE WHEN partida.par_gol_mand > partida.par_gol_visi THEN 1 ELSE 0 END ) AS VITORIAS
, SUM( CASE WHEN partida.par_gol_mand = partida.par_gol_visi THEN 1 ELSE 0 END ) AS EMPATES
, SUM( CASE WHEN partida.par_gol_mand < partida.par_gol_visi THEN 1 ELSE 0 END ) AS DERROTAS
FROM team
INNER JOIN partida
ON team.tim_cod_inscri_time = partida.par_cod_partida
ORDER BY ( VITORIAS * 3 + EMPATES ) DESC;
ERROR 1247(42S22):不支持参考'VITORIAS'(参考 小组职能)
答案 0 :(得分:0)
在此代码中很难完全理解您的目标。但是,这可能就是你所追求的:
SELECT SUM(VITORIAS), SUM(EMPATES), SUM(DERROTAS), tim_cod_inscri_time FROM
(SELECT
(CASE WHEN partida.par_gol_mand > partida.par_gol_visi THEN 1 ELSE 0 END ) AS VITORIAS ,
(CASE WHEN partida.par_gol_mand = partida.par_gol_visi THEN 1 ELSE 0 END ) AS EMPATES ,
(CASE WHEN partida.par_gol_mand < partida.par_gol_visi THEN 1 ELSE 0 END ) AS DERROTAS
FROM team INNER JOIN partida ON team.tim_cod_inscri_time = partida.par_cod_partida)
AS teamrecord
GROUP BY tim_cod_inscri_time
ORDER BY ( VITORIAS * 3 + EMPATES ) DESC;
我将SUM
从内部表中拉出来,并分别总结了胜利。另外,我给子查询一个任意名称teamrecord
。这是你要的吗?