软件下载 | 资讯教程 | 最近更新 | 下载排行 | 一键转帖 | 发布投稿
您的位置:最火下载站 > 网络编程 > SQL SERVER > 查询数据库指定字段重复项的一条数据

查询数据库指定字段重复项的一条数据

  烈火网(LieHuo.Net)教程 如何SQL SERVER 查询数据库指定字段重复项的一条数据,今天小编在博客园看到该问题的实例命令代码,现在特别转载了分享给各位访客,希望对您有所帮助。

以下为引用的内容:
CREATE TABLE [cc] (
[a] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[b] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[c] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO

--数据:
"1","a","c"
"2","a","c"
"3","b","c"
"4","c","d"
"5","c","d"


CREATE TABLE [temp] (
[id] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO


--实现
declare @cname nvarchar(20)
declare @mname nvarchar(20)
Declare Cur Cursor For select distinct b,c from cc
Open Cur
Fetch next From Cur Into @cname,@mname
While @@fetch_status=0
Begin
insert into temp
select top 1 a from cc where b=@cname and c=@mname
Fetch next From Cur Into @cname,@mname
End
Close Cur
Deallocate Cur


select * from cc

select * from cc where a in (select id from temp)

    相关阅读
    栏目导航
    推荐软件