Reputation: 23
SELECT "region", sum("items"), sum("actcost")
FROM "apr","Regions"
WHERE "bnfname" LIKE 'Flucloxacillin %' AND apr.sha=Regions.sha
GROUP BY "region"
Following error given:
ERROR: missing FROM-clause entry for table "regions"
Upvotes: 2
Views: 9685
Reputation: 1774
try this:
SELECT "region", sum("items"), sum("actcost")
FROM "apr","Regions"
WHERE "bnfname" LIKE 'Flucloxacillin %' AND "apr"."sha"="Regions"."sha"
GROUP BY "region"
Upvotes: 1
Reputation: 2375
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
Or use join
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
Upvotes: 0