我有一张“很好”的 table 。它包含一列 app_rate_unit(类型:nvarchar)。
我的目标是计算表中每个不同的值,并让 DBMS (MS Server 2005) 给我出现次数最多的值。
这是我的代码:
SELECT MAX(app_rate_unit) AS MAX_APP
FROM (SELECT app_rate_unit, COUNT(*) AS co
FROM dbo.well AS w
GROUP BY app_rate_unit
) AS derivedtbl_1
然而,它的问题是,我的 DBMS 实际上为我提供了最低的计数。
SideQuestion:如何在计数时过滤外键(在表中)和 NOT NULL(在 app_rate_unit 中)?
最佳答案
select top 1 app_rate_unit, count(*) from dbo.well
group by app_rate_unit
order by count(*) desc
关于sql - SELECT MAX of COUNT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11646401/