select count(MONTH) as nums ,MONTH from FA_POLLING_DETAIL group by MONTH
想求出count数最小的month,请问大神如何可以高效的获取。
我通过下面的方式获得了,但是感觉效率肯定超低
select month from (select count(MONTH) as nums ,MONTH from FA_POLLING_DETAIL group by MONTH) where NUMS = (select min(nums) from (select count(MONTH) as nums ,MONTH from FA_POLLING_DETAIL group by MONTH))
------解决方案--------------------
这样?
select top 1 count(MONTH) as nums ,MONTH from FA_POLLING_DETAIL group by MONTH order by nums desc
------解决方案--------------------
order by count(MONTH) desc
这样排序,也行的.
------解决方案--------------------
获取count(month)最小的month,如果201410的count(month)为5,201411的count(month)也为5。这样你要的结果是
结果一:
201410
201411
结果二:
201411
------解决方案--------------------
ORDER BY 1 DESC