【问题标题】:Find for all those records having same Last Name and same Postcode查找所有具有相同姓氏和相同邮政编码的记录
【发布时间】:2017-02-08 17:41:48
【问题描述】:

我需要一个 SQL 脚本来查找数据库中具有相同姓氏和相同邮政编码的所有记录

例如:

first_Name   Last_Name  Postcode
Nathan       Yorke      SY3 0NN
Calum        Yorke      SY3 0NN

非常感谢

【问题讨论】:

  • 你的 DBMS 是什么?是否支持COUNT() OVER

标签: sql postal-code


【解决方案1】:

最简单的方法是使用窗口函数:

select t.*
from (select t.*, count(*) over (partition by last_name, postcode) as cnt
      from t
     ) t
where cnt > 1;

【讨论】:

    猜你喜欢
    • 2019-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多