表结构如下图,找出productid 列中出现次数最多的productid ,
语句为:select top 1 count( productid) as mycount,productid from dbo.CatalogsProducts group by productid order by mycount desc
如果要找出出现次数大于7的;
应该为:select top 10 count( productid) as mycount,productid from dbo.CatalogsProducts group by productid having count( productid)>7 order by mycount desc
注意:这个的count( productid)>7不能换为mycount>7,要报“列名 'mycount' 无效”的错误。