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
2,表数据如下:
ListID ComID
3 1
8 2
9 2
10 4
11 4
12 4
怎么写SQL,按照ComID的出现次数排序,如上面结果为
ComID
4
2
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
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
可以,但是我的表中有多个字段,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 运算符。
请大家再帮忙看一下~-~
strIP.substring(0, strIP.lastIndexOf(".")+1)+"*";