日期:2014-05-18  浏览次数:20415 次

如何生成这样的表!
SQL数据库中有个表backlog,里面有个字段IP,IP中的每个数据都不一定唯一的。
现在我想在网页中做一个表格,表中格2个项,分别为IP,IPcount(此字段是来显示backlog中该IP出现的次数)
例如: IP IPcount
  192.168.1.1 50
  192.168.1.2 70
大家是否能给个思路,用gridview能否实现,最好给个例子。

------解决方案--------------------
例如: IP IPcount 
192.168.1.1 50 
192.168.1.2 70 

楼主说要实现这样的结果,这是通过sql语句去实现的。然后把这样的结果绑定到gridview中就可以了``

sql语句:

select ip,count(1) as ipcount from backlog group by ip

绑定时直接绑定ip,ipcount两个字段就OK了
------解决方案--------------------
select ip,count(ipcount) as ipcount from backlog group by ip
------解决方案--------------------
多好实现呀,写个sql
SQL code

select a.IP,a.[IPcount] from 
(SELECT IP, count(IP) as [IPcount]
FROM backlog 
GROUP BY IP WITH CUBE) a
where IP is not null

------解决方案--------------------
select ip,sum(ipcount) as ipcount from backlog group by ip
------解决方案--------------------
应该是最前面有空格原因,我故意加了个空格就出现你的问题了

select replace(IP,' ','') as IP,count(IP) as IPcount from backlog group by replace(IP,' ','') order by IP asc

这样应该可以了,试试