从关系中选择最常见的值-SQL语句 [英] Selecting the most common value from relation - SQL statement

查看:72
本文介绍了从关系中选择最常见的值-SQL语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有一个表,该表中有很多记录,有些记录的其中一个列共享相同的值.例如

I have a table within my database that has many records, some records share the same value for one of the columns. e.g.

|  id  |  name  |  software  |
______________________________
|  1   |  john  |  photoshop |
|  2   |  paul  |  photoshop |
|  3   |  gary  |  textmate  |
|  4   |  ade   |  fireworks |
|  5   |  fred  |  textmate  |
|  6   |  bob   |  photoshop |

我想通过使用SQL语句返回最常出现的软件的值.

I would like to return the value of the most common occurring piece of software, by using an SQL statement.

因此,在上面的示例中,所需的SQL语句将比其他任何软件更频繁地返回"photoshop".

So in the example above the required SQL statement would return 'photoshop' as it occurs more than any other piece of software.

这可能吗?

谢谢您的时间.

推荐答案

select top 1 software 
from your_table 
group by software
order by count(*) desc 

这篇关于从关系中选择最常见的值-SQL语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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