0

我试图修复这个请求几个小时没有成功,所以我希望你们能帮助我找出问题所在:

SELECT ((
    SELECT DISTINCT *
    FROM (
        SELECT REPLACE(source_name, "+", "") AS name
        FROM events
        WHERE source_name!=""
        UNION
        SELECT REPLACE(target_name, "+", "") AS name
        FROM events
        WHERE target_name!=""
    )
) AS player_name,
(
    SELECT COUNT(*)
    FROM events
    WHERE source_name=player_name AND event_name="beforePlayerBan"
) as nbr_bans,
(
    SELECT COUNT(*)
    FROM events
    WHERE source_name=player_name AND event_name="beforePlayerKick"
) as nbr_kicks,
(
    SELECT COUNT(*)
    FROM events
    WHERE
        (source_name=player_name OR target_name=player_name)
        AND event_name="afterBattleStarted"
) as nbr_battles,
(
    SELECT COUNT(*)
    FROM events
    WHERE source_name=player_name AND result=0
) as nbr_wins,
(
    SELECT COUNT(*)
    FROM events
    WHERE target_name=player_name AND result=0
) as nbr_defeats,
(
    SELECT COUNT(*)
    FROM events
    WHERE (source_name=player_name OR target_name=player_name) AND result=1
) as nbr_ties,
(
    SELECT COUNT(*)
    FROM events
    WHERE (source_name=player_name OR target_name=player_name) AND result=2
) as nbr_forfeits

错误是 SQLSTATE[42000]:语法错误或访问冲突:1248 每个派生表都必须有自己的别名,这很奇怪,因为我确实给每个表都赋予了自己的别名

4

1 回答 1

1

您的第一个子查询似乎缺少别名:

SELECT ((
       SELECT DISTINCT *
       FROM (
              SELECT REPLACE(source_name, "+", "") AS name
              FROM events
              WHERE source_name!=""
              UNION
              SELECT REPLACE(target_name, "+", "") AS name
              FROM events
              WHERE target_name!=""
    )  myMissingAlias -- alias needed here
) AS player_name, 

另外,除非您没有发布完整的查询,否则我认为您可能会错过决赛)

于 2012-09-26T21:01:09.707 回答