group by b.COUNTRY_CODE,b.YEAR group by的字段必须在select列表中出现
select a.COUNTRY_NAME,b.PEOPLE,b.COUNTRY_CODE,b.YEAR from BASE2_COUNTRY a ,DATA2_WORLD_JJZB b where a.COUNTRY_CODE=b.COUNTRY_CODE and b.YEAR>=1998 and b.YEAR<=1999 group by b.COUNTRY_CODE,b.YEAR order by b.COUNTRY_CODE,b.YEAR DESC ;我这样改后,问题依旧
select a.COUNTRY_NAME,b.PEOPLE,b.COUNTRY_CODE,b.YEAR from BASE2_COUNTRY a ,DATA2_WORLD_JJZB b where a.COUNTRY_CODE=b.COUNTRY_CODE and b.YEAR>=1998 and b.YEAR<=1999 group by a.county_name,b.COUNTRY_CODE,b.YEAR order by b.COUNTRY_CODE,b.YEAR DESC ;这样应该可以了 分组的条件应该都列在group by 子句里
这样写:select a.COUNTRY_NAME,b.PEOPLE,b.COUNTRY_CODE,b.YEAR from BASE2_COUNTRY a ,DATA2_WORLD_JJZB b where a.COUNTRY_CODE=b.COUNTRY_CODE and b.YEAR>=1998 and b.YEAR<=1999 group by a.COUNTRY_NAME,b.PEOPLE,b.COUNTRY_CODE,b.YEAR order by b.COUNTRY_CODE,b.YEAR DESC ;group by的字段必须在select中出现
改成以下就可以通过了select b.COUNTRY_CODE,b.YEAR from BASE2_COUNTRY a ,DATA2_WORLD_JJZB b where a.COUNTRY_CODE=b.COUNTRY_CODE and b.YEAR>=1998 and b.YEAR<=1999 group by b.COUNTRY_CODE,b.YEAR order by b.COUNTRY_CODE,b.YEAR DESC ;但是如果加入a.COUNTRY_NAME,b.PEOPLE 在select 字段中后,怎么又出错,即改为: select b.COUNTRY_CODE,b.YEAR,a.COUNTRY_NAME,b.PEOPLE from BASE2_COUNTRY a ,DATA2_WORLD_JJZB b where a.COUNTRY_CODE=b.COUNTRY_CODE and b.YEAR>=1998 and b.YEAR<=1999 group by b.COUNTRY_CODE,b.YEAR order by b.COUNTRY_CODE,b.YEAR DESC ; 问题依旧那总不能让我在select出的列都在放到group by中去吧,那多麻烦呢, 怎么解决呀
分组条件必须列在group by 后,没有办法
select * from (select a.COUNTRY_NAME,b.PEOPLE from BASE2_COUNTRY a ,DATA2_WORLD_JJZB b where a.COUNTRY_CODE=b.COUNTRY_CODE and b.YEAR>=1998 and b.YEAR<=1999 group by b.COUNTRY_CODE,b.YEAR order by b.COUNTRY_CODE,b.YEAR DESC)
group by 后跟的列 必须是 select 子句中的列
不知你为什么要用group by?
改成下面的形式,用一个嵌套 select code,year,country_name,people from (select b.COUNTRY_CODE code,b.YEAR year,a.COUNTRY_NAME country_name,b.PEOPLE people from BASE2_COUNTRY a ,DATA2_WORLD_JJZB b where a.COUNTRY_CODE=b.COUNTRY_CODE and b.YEAR>=1998 and b.YEAR<=1999) group by code,year order by code,year DESC
group by的字段必须在select列表中出现
where a.COUNTRY_CODE=b.COUNTRY_CODE and b.YEAR>=1998 and b.YEAR<=1999
group by b.COUNTRY_CODE,b.YEAR
order by b.COUNTRY_CODE,b.YEAR DESC ;我这样改后,问题依旧
where a.COUNTRY_CODE=b.COUNTRY_CODE and b.YEAR>=1998 and b.YEAR<=1999
group by a.county_name,b.COUNTRY_CODE,b.YEAR
order by b.COUNTRY_CODE,b.YEAR DESC ;这样应该可以了
分组的条件应该都列在group by 子句里
where a.COUNTRY_CODE=b.COUNTRY_CODE and b.YEAR>=1998 and b.YEAR<=1999
group by a.COUNTRY_NAME,b.PEOPLE,b.COUNTRY_CODE,b.YEAR
order by b.COUNTRY_CODE,b.YEAR DESC ;group by的字段必须在select中出现
where a.COUNTRY_CODE=b.COUNTRY_CODE and b.YEAR>=1998 and b.YEAR<=1999
group by b.COUNTRY_CODE,b.YEAR
order by b.COUNTRY_CODE,b.YEAR DESC ;但是如果加入a.COUNTRY_NAME,b.PEOPLE 在select 字段中后,怎么又出错,即改为:
select b.COUNTRY_CODE,b.YEAR,a.COUNTRY_NAME,b.PEOPLE from BASE2_COUNTRY a ,DATA2_WORLD_JJZB b
where a.COUNTRY_CODE=b.COUNTRY_CODE and b.YEAR>=1998 and b.YEAR<=1999
group by b.COUNTRY_CODE,b.YEAR
order by b.COUNTRY_CODE,b.YEAR DESC ;
问题依旧那总不能让我在select出的列都在放到group by中去吧,那多麻烦呢, 怎么解决呀
where a.COUNTRY_CODE=b.COUNTRY_CODE and b.YEAR>=1998 and b.YEAR<=1999
group by b.COUNTRY_CODE,b.YEAR
order by b.COUNTRY_CODE,b.YEAR DESC)
select code,year,country_name,people from
(select b.COUNTRY_CODE code,b.YEAR year,a.COUNTRY_NAME country_name,b.PEOPLE people from BASE2_COUNTRY a ,DATA2_WORLD_JJZB b
where a.COUNTRY_CODE=b.COUNTRY_CODE and b.YEAR>=1998 and b.YEAR<=1999)
group by code,year
order by code,year DESC