表如下->ip                           address
192.168.1.1                  aaa                          
192.168.1.2                  蜘蛛A
192.168.1.2                  蜘蛛A
192.168.1.2                  蜘蛛A
192.168.1.3                  蜘蛛B
192.168.1.3                  蜘蛛B
192.168.1.4                  www.123.com
192.168.1.4                  www.123.com
192.168.1.5                  www.abc.com
192.168.1.6                  www.ff.com
192.168.1.6                  www.abc.com如上表所示..
我有个条件,address列里面出现"蜘蛛"和"12"字样的,都不应该计入总数
输出的个数应该为:3
也就是->192.168.1.1 192.168.1.5 192.168.1.6 共三个PS:应该用group by 和like吧好像...

解决方案 »

  1.   

    在这里已提供答案了,别再重发了 OKhttp://topic.csdn.net/u/20111220/20/2f88da4d-bdf0-4336-9ddc-49ec96a0f045.html#replyachor
      

  2.   

    你这个可以用 DISTINCT 
      

  3.   

    select distinct ip from t1  where charindex(address,'蜘蛛')<=0 and charindex(address,'12')<=0
      

  4.   

    string sql="select count(DISTINCT address)as mycount from table";
      

  5.   

    string sql="select count(DISTINCT address)as mycount from table where address like '%蜘蛛%' and like '%12%'";
      

  6.   

    string sql="select count(DISTINCT ip)as myip from table where address like '%蜘蛛%' and like '%12%'";不好意思,上面的应是count(DISTINCT ip)as myip
      

  7.   

    我有个条件,address列里面出现"蜘蛛"和"12"字样的,都不应该计入总数
    没注意这个 string sql="select count(DISTINCT ip)as myip from table where address NOT like '%蜘蛛%' and like '%12%'";