首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Access >

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

2012-03-02 
求这句sql语句的正确写法selectcount(*)AS[CountryCount],[Country]from[IPRecord]groupby[Country]orderb

求这句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表示第一个字段


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

热点排行