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

30分请问,小弟我这条语句错在哪里

2012-03-01 
30分请教,我这条语句错在哪里?我想统计数据库里,哪种产品的数量最多.(前10位)我用下面的SQL语句:selectTop

30分请教,我这条语句错在哪里?
我想统计数据库里,哪种产品的数量最多.(前10位)

我用下面的SQL语句:

select   Top   10     parts   ,count(parts)as   total    
from   information    
group   by   parts

结果如下:

partstotal
101010195
101010265
1010104185
10101051
101010644
101010721
10101081
10101142
10101158
1010500228


可是结果却不对.

因为数据库内象   1510102   /1510104   这样的产品数据有的共有100多条,为什么却没有统计进来?

[解决办法]
select parts ,count(parts)as total
from information
group by parts

[解决办法]
select Top 10 parts ,count(parts)as total
from information
group by parts
Order By total Desc --加上這個
[解决办法]
--LZ沒有加order by ,就默認order by part了
select Top 10 parts ,count(parts)as total
from information
group by parts
order by total Desc

热点排行