按字符串的第一个字母分组

发布于 2024-10-17 03:35:31 字数 167 浏览 6 评论 0原文

我有一个 Person 表,其中有大量记录,并且想按其中重复的人员进行分组, 根据其中一个要求,人员是重复的,如果他们具有相同的姓氏,并且名字的第一个字母相等,所以我想按名字和姓氏的第一个字母进行分组,有没有办法在sql中进行分组像这样?我在C#中需要这个,所以可以完成一些代码处理,但是人数巨大,所以它应该是快速算法。

I have a Person table, with huge number of records, and want to group by duplicate persons in it,
by one of requirements persons are duplicates, if they have the same family name, and the first letter of first names are equal, so I want to group by first name, and first letter of family name, is there a way to group in sql like this? I need this in C#, so some code processing could be done, but the number of persons is huge, so it should be fast algorithm.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

可爱暴击 2024-10-24 03:35:31

如果我理解正确的话,从 SqlServer 你可以做类似的事情

SELECT  DISTINCT
        Surname,
        LEFT(FirstName,1) FirstNameLetter
FROM    Persons

除此之外,我们需要更多的细节。表模式、预期结果集等...

If I understand you correctly, from SqlServer you can do something like

SELECT  DISTINCT
        Surname,
        LEFT(FirstName,1) FirstNameLetter
FROM    Persons

Other than that, we will need a little bit more detail. Table schema, expected result set, etc...

音盲 2024-10-24 03:35:31
SELECT MEMBER.MEMBER_FIRSTNAME, COUNT(MEMBER.MEMBER_LASTNAME)
FROM dbo.MEMBER
GROUP BY MEMBER.MEMBER_FIRSTNAME, SUBSTRING(MEMBER.MEMBER_LASTNAME, 1,1)
HAVING COUNT(MEMBER.MEMBER_LASTNAME) > 1

此查询将为您提供所有(在本例中为成员),其中多个成员的名字相同且姓氏的第一个字母相同。换句话说,重复您所定义的内容。

SELECT MEMBER.MEMBER_FIRSTNAME, COUNT(MEMBER.MEMBER_LASTNAME)
FROM dbo.MEMBER
GROUP BY MEMBER.MEMBER_FIRSTNAME, SUBSTRING(MEMBER.MEMBER_LASTNAME, 1,1)
HAVING COUNT(MEMBER.MEMBER_LASTNAME) > 1

This query will give you all (members in this case) where the first name is the same and the last name's first letter is the same for more than one member. In other words duplicates as you've defined it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文