【问题标题】:How to find the total count of duplicate name如何查找重复名称的总数
【发布时间】:2016-07-24 17:39:18
【问题描述】:

我有一张桌子

CREATE TABLE [dbo].[tblTeams](
[Id] [int] IDENTITY(1,1) NOT NULL,
[TeamId] [varchar](5) NOT NULL,
[TeamName] [varchar](100) NOT NULL,
[PlayerName] [varchar](100) NOT NULL,
[PlayerNickName] [varchar](100) NULL,
[Status] [int] NULL

现在我写了一个存储过程:

Alter Proc [dbo].[SpGetDuplicateName]
    @PlayerName varchar(200)
AS
Begin
(
    Select PlayerName,TeamName,TeamId 
    from tblTeams where PlayerName like @PlayerName 
)
END

现在我想返回名称被复制的次数

需要帮助

提前致谢

【问题讨论】:

  • 请显示一些示例输入和预期输出

标签: sql-server stored-procedures sql-server-2008-r2


【解决方案1】:

对 Ullas 查询的小改动... HAVING 将只返回骗子

SELECT PlayerName, COUNT(PlayerName) AS [Count]
FROM tblTeams
WHERE PlayerName LIKE '%word_to_search%'
GROUP BY PlayerName;
HAVING COUNT(*)>1

【讨论】:

    【解决方案2】:

    COUNTGROUP BY 一起使用。

    查询

    SELECT PlayerName, COUNT(PlayerName) AS [Count]
    FROM tblTeams
    WHERE PlayerName LIKE '%word_to_search%'
    GROUP BY PlayerName;
    

    【讨论】:

    • 非常有帮助。@Ullas
    猜你喜欢
    • 2013-02-21
    • 2013-11-07
    • 2013-10-31
    • 2017-01-23
    • 2014-06-02
    • 1970-01-01
    • 1970-01-01
    • 2019-10-09
    • 1970-01-01
    相关资源
    最近更新 更多