读书人

求这句sql语句的正确写法,该如何解决

发布时间: 2012-03-02 14:40:28 作者: rapoo

求这句sql语句的正确写法
select count(*) AS [CountryCount],[Country] from [IPRecord] group by [Country] order by CountryCount desc

意图:从IPRecord表里按 Country 分组,计算出每组的数CountryCount 然后按CountryCount从大到小排

这句sql语句在sqlserver中是没有问题的。
但是在access中这样写不行。 该怎么办?

[解决办法]
select count(*) AS [CountryCount],[Country] from [IPRecord] group by [Country]
order by count(*) desc

[解决办法]
Access中不能用别名在Order by中,可以如下:


select count(*) AS [CountryCount],[Country]
from [IPRecord]
group by [Country]
order by count(*) desc




select count(*) AS [CountryCount],[Country]
from [IPRecord]
group by [Country]
order by 1 desc --注意,这里1表示第一个字段


或者用你写的子查询那种方式。

读书人网 >Access

热点推荐