2014-10-10 101 views
0

當前我有以下代碼,第I部分和第II部分工作正常。 但是,當我嘗試聯盟,兩個臨時表,它讓我給我錯誤消息 「未知的列'名稱'在'字段列表'」,即使我已經嘗試了很多時間來更改名稱在臨時表中提交'姓名'。錯誤消息:字段列表中的字段列表中的未知列

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; 

有人可以提供一些提示嗎?我得到這個錯誤味精,因爲名稱是一個特殊的關鍵字在SQL?

回答

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; 

所以你在Group Bytmp.name

+0

謝謝,我試過了,仍然沒有工作。似乎它無法檢測到查詢中的所有'名稱'。 – Mona 2014-10-10 13:31:22

+0

爲inp_cnt和ar_cnt表,我已經打印出來了,他們兩個在結果中都有正確的名稱和c。 – Mona 2014-10-10 13:32:07

+0

@mona,嘗試向'SELECT'部分添加'tmp.'別名。 – christiandev 2014-10-10 13:58:57

相關問題