错误消息:包含该字段的表中字段列表中的未知列

时间:2014-10-10 11:31:00

标签: sql

目前我有以下代码,第一部分和第二部分工作正常。 但是,当我尝试联盟时,两个临时表,它让我给我错误信息 “即使我已经多次尝试更改临时表中提交的”名称“的名称,”字段列表中的未知列'名称'仍然存在。“

CREATE TEMPORARY TABLE IF NOT EXISTS inp_cnt AS(
SELECT a.name, count(DISTINCT ad.pub_id) AS c
FROM author AS a
INNER JOIN authored AS ad ON a.id = ad.author_id
INNER JOIN inproceedings AS inp ON ad.pub_id = inp.pub_id
WHERE inp.booktitle = "SIGMOD conference" OR inp.booktitle = "KDD" OR inp.booktitle = "VLDB"
GROUP BY ad.author_id);

CREATE TEMPORARY TABLE IF NOT EXISTS ar_cnt AS(
SELECT a.name,  count(DISTINCT ad.pub_id) AS c
FROM author AS a
INNER JOIN authored AS ad ON a.id = ad.author_id
INNER JOIN article AS ar ON ad.pub_id = ar.pub_id
WHERE ar.journal = "PVLDB"
GROUP BY ad.author_id);


SELECT name,sum(c) AS total
FROM (
SELECT name,c FROM inp_cnt
UNION ALL
SELECT name, c FROM ar_cnt
) as tmp
GROUP BY name
ORDER BY total DESC
LIMIT 20;

有人可以给出一些暗示吗?我收到此错误消息,因为name是sql中的特殊关键字

1 个答案:

答案 0 :(得分:0)

尝试将上一个查询更改为:

SELECT  tmp.name
       ,SUM(tmp.c) AS total
FROM    ( SELECT    name
                   ,c
          FROM      inp_cnt
          UNION ALL
          SELECT    name
                   ,c
          FROM      ar_cnt
        ) AS tmp
GROUP BY tmp.name
ORDER BY total DESC
LIMIT 20;

所以tmp.name中有Group By