我有一张桌子
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
现在我想返回一个名称被复制多少次的计数
需要帮助
提前致谢
答案 0 :(得分:3)
对Ullas查询的小扭曲...... HAVING将仅返回欺骗
SELECT PlayerName, COUNT(PlayerName) AS [Count]
FROM tblTeams
WHERE PlayerName LIKE '%word_to_search%'
GROUP BY PlayerName;
HAVING COUNT(*)>1
答案 1 :(得分:2)
将COUNT
与GROUP BY
一起使用。
<强>查询强>
SELECT PlayerName, COUNT(PlayerName) AS [Count]
FROM tblTeams
WHERE PlayerName LIKE '%word_to_search%'
GROUP BY PlayerName;