SELECT MAX COUNT [英] SELECT MAX of COUNT

查看:137
本文介绍了SELECT MAX COUNT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表好。它包含一个列app_rate_unit(类型:nvarchar)。
我的目标是计算表中的每个不同的值,并让DBMS(MS Server 2005)给我最多的一个。

I have a table "well". It contains a column app_rate_unit (type: nvarchar). My goal is to count every distinct value in the table and let the DBMS (MS Server 2005) give me the most occurring one.

这是我的代码:

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实际上给我最低的计数。

The poblem with it is however, that my DBMS actually delivers the lowest count to me.

SideQuestion:如何过滤外键(在表中)和NOT

SideQuestion: How do I filter for a foreign key (in the table) and NOT NULL (in app_rate_unit) when counting?

推荐答案

select top 1 app_rate_unit, count(*) from dbo.well
group by app_rate_unit
order by count(*) desc

这篇关于SELECT MAX COUNT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆