这个SQL语句在语法上有什么问题吗?

时间:2013-04-13 02:14:25

标签: sql syntax sqlite

当我尝试在mysqlite3中运行此查询时,我一直收到错误:

SELECT Region_DESC, AgeGroup, Population
(select REGION, sum(POPULATION) as Population, '0-15' AS AgeGroup
from STATS
Where Age between 0 and 15
group by REGION
union
Select REGION, SUM(POPULATION) as Population, '16-30' As AgeGroup
from STATUS
Where Age between 16 and 30
group by REGION) s
join REGION on REGION_CD = REGION

我收到以下错误: 错误:靠近“SELECT”:语法错误

查询是否有任何问题,语法方面?

3 个答案:

答案 0 :(得分:2)

在“人口”一词之后,你遗漏了FROM

答案 1 :(得分:2)

您的查询错误。你基本上有:

SELECT something
(select somethingelse FROM somethingelsetable) s
join REGION on REGION_CD = REGION

我猜你在括号前缺少FROM ......

答案 2 :(得分:0)

错误的查询...在第一行中缺少From Clause。