求这句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表示第一个字段
或者用你写的子查询那种方式。