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

关于聚合函数的问题
先执行 SELECT count([ID]) FROM TradeList group by [seller_nick]
得到如下一列数据:
 2
 13
 31328
 71
 4537
 530
 1

再取这一列数据中最小的 就是 1

尝试了这么写 SELECT min(count([ID])),[seller_nick] FROM TradeList group by [seller_nick]
但是 不能对包含聚合或子查询的表达式执行聚合函数。 

有没有其他方法 一句sql能实现上面功能的? 麻烦高手帮忙解答下

------解决方案--------------------
SQL code

select min([count]) from(
SELECT count([ID]) as [count] FROM  TradeList group by [seller_nick]
)t

------解决方案--------------------
嵌套查询即可。
------解决方案--------------------
SQL code

SELECT TOP 1 count([ID]) FROM TradeList group by [seller_nick]
ORDER BY count([ID]) ASC

------解决方案--------------------
SQL code
select MIN (ID),[seller_nick]from (
SELECT count([ID]) id ,[seller_nick] FROM TradeList group by [seller_nick])a

------解决方案--------------------

探讨

SQL code

SELECT TOP 1 count([ID]) FROM TradeList group by [seller_nick]
ORDER BY count([ID]) ASC