0

我无法创建视图。您可以在下面找到我的代码。有人可以帮助我吗?

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): Reference 'VITORIAS' not supported (reference to group function)

4

1 回答 1

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. 这就是你想要的吗?

于 2012-12-04T03:41:26.783 回答