关于多行出现次数总和的 SQL 查询 [英] SQL query concerning the sum of occurrences for multiple rows

查看:36
本文介绍了关于多行出现次数总和的 SQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一点帮助才能使此 SQL 查询正常工作.假设我有一张这样的桌子:

I need a little bit of help in getting this SQL query to work. Say I have a table like this:

                Test

    +--------+--------+--------+
    |  Name  |  Date  |Location|
    +--------+--------+--------+
    | Steven |03-05-12| 120000 |
    +--------+--------+--------+
    | James  |04-09-11| 110000 |
    +--------+--------+--------+
    | James  |06-22-11| 110000 |
    +--------+--------+--------+
    |  Ryan  |10-11-13| 250000 |
    +--------+--------+--------+
    |  Ryan  |12-19-13| 180000 |
    +--------+--------+--------+

我需要找到在同一地点进行了多次测试"的每个人的姓名.

I need to find the name of every individual who has taken a "test" more than one time, but at the same location.

例如,James 会被选中,因为他在位置 110000 进行了两次测试,但 Ryan 不会被选中,因为他在两个不同的位置进行了两次测试.

For example, James would be selected because he took two tests at location 110000, but Ryan would not be selected because he took his two tests at two different locations.

谢谢!

推荐答案

select name
  from tbl
 group by name,
          location
having count(*) > 1

这篇关于关于多行出现次数总和的 SQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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