如何获取Sql表中的最大使用值数 [英] How Can I Get The Maximum Number Of Using Value In A Sql Table
本文介绍了如何获取Sql表中的最大使用值数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有数据如
i have the data like
ID UnitId TIME
1 4 01/01/2012
2 1 02/02/2012
3 1 03/02/2012
4 3 04/01/2012
5 1 04/06/2012
6 2 01/03/2012
现在我如何从最大时间使用单位ID 1的表中获得UnitId 1
Now how can i get UnitId 1 from that table where unit id 1 is used in maximum time
推荐答案
SELECT Top 1 UnitId FROM Table_Name GROUP BY UnitId ORDER BY COUNT(UnitId ) DESC
select top 1 unitid from
(
select count(unitid) as total,UnitID from Unit
group by unitid
)as t
order by t.total desc
请接受,如果它为你工作.....
please accept if its work for you.....
这篇关于如何获取Sql表中的最大使用值数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文