1,正则怎么写,把IP地址的最后一位替换为星号,如220.168.55.* 。
2,表数据如下:
   ListID  ComID
   3        1
   8        2
   9        2
   10       4
   11       4
   12       4
怎么写SQL,按照ComID的出现次数排序,如上面结果为
    ComID
    4
     2
     1

解决方案 »

  1.   


    declare @tb table(ListID int,ComID int)
    Insert @tb(ListID,ComID)
     select  3    ,    1 union all
     select  8    ,    2 union all
     select  9    ,    2 union all
     select 10    ,  4 union all
     select 11    ,  4 union all
     select 12    ,  4 select ComID from @tb group by ComID ORDER BY count(ComID) DESC
      

  2.   

    SELECT ComID FROM table_name 
        INNER JOIN (SELECT ComID,COUNT(ListID) AS cnt FROM table_name GROUP BY ComID) AS table_2 
            ON table_2.ComID=table_name.ComID 
        ORDER BY cnt
      

  3.   

    ((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)这个是IP的正则,把最后一个"."号后面的内容换成"*"就行了~
      

  4.   

    第2个问题.select ComID from table group by ComID order by count(*) desc
      

  5.   

    select ComID from table_name a where not exists(select 1 from table_name where a.ComID=ComID and a.ListID<ListID) order by a.ComID desc
      

  6.   

    非常感谢大家的帮忙,select ComID from @tb group by ComID ORDER BY count(ComID) DESC
    可以,但是我的表中有多个字段,ListID,ComID,Commentator,...改为select * from CommentList group by ComID ORDER BY count(ComID) DESC,就提示:
    选择列表中的列 'CommentList.ListID' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。我加上group by ComID,ListID
    又提示:
    选择列表中的列 'CommentList.Commentator' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中我把表中全部的字段把加中group by后面,最终提示:不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符。
    请大家再帮忙看一下~-~
      

  7.   

    IP地址的最后一位替换为星号,如220.168.55.* 不用正则
    strIP.substring(0, strIP.lastIndexOf(".")+1)+"*";