错误:缺少表的FROM子句条目

时间:2016-01-10 18:07:38

标签: postgresql

SELECT "region", sum("items"), sum("actcost")
FROM "apr","Regions"
WHERE "bnfname" LIKE 'Flucloxacillin %' AND apr.sha=Regions.sha
GROUP BY "region"

发出以下错误:

  

错误:缺少表“region”的FROM子句条目

2 个答案:

答案 0 :(得分:1)

试试这个:

SELECT "region", sum("items"), sum("actcost")
FROM "apr","Regions"
WHERE "bnfname" LIKE 'Flucloxacillin %' AND "apr"."sha"="Regions"."sha"
GROUP BY "region"

答案 1 :(得分:0)

SELECT apr.region, 
       SUM(apr.items), 
       SUM(apr.actcost) 
FROM   apr, 
       Regions 
WHERE  apr.bnfname LIKE 'Flucloxacillin %' 
       AND apr.sha = regions.sha 
GROUP  BY apr.region

或使用加入

SELECT apr.region, 
       SUM(apr.items), 
       SUM(apr.actcost) 
FROM   apr 
       join regions 
         ON apr.sha = regions.sha 
WHERE  apr.bnfname LIKE 'Flucloxacillin %' 
GROUP  BY apr.region