aa 0003
aa 0004
aa 0005
bb 3112
bb 4221
bb 0012都是字符串,我想查询结果是
aa 0003
bb 3112
aa 0004
aa 0005
bb 3112
bb 4221
bb 0012都是字符串,我想查询结果是
aa 0003
bb 3112
解决方案 »
- 查找相同的值(二)
- 年份转换
- 昨天别人的问题,如何得到其中最大的值。
- SqlDumpExceptionHandler: 进程 52 发生了严重的异常 c0000005 EXCEPTION_ACCESS_VIOLATION。SQL
- 比较两种SQL关系的设计
- 循环插入一年内的时间段
- 创建临时表的语句不能写两次,怎么办?
- 为什么我在本地调试时,我的asp联不上本地已经配制好数据源的sql server 2000呢?
- SQL超级复杂关系语句,教新手吧!大送分
- 有谁知道上传和下载系统源代码的地方(ASP源代码)(在线等待)
- 为交流方便建立群33367343(数据库设计管理),欢迎各位加入共同探讨
- 怎么转化带 % 的 ?
insert into #
select 'aa','0003'
union all select 'aa','0004'
union all select 'aa','0005'
union all select 'bb','3112'
union all select 'bb','4221'
union all select 'bb','0012'select * from #
where code=(select top 1 code from # t where t.name=#.name)drop table #
insert into #
select 'aa','0003'
union all select 'aa','0004'
union all select 'aa','0005'
union all select 'bb','3112'
union all select 'bb','4221'
union all select 'bb','0012'select * from # a
where exists (select 1 from # where name=a.name and code>a.code)
drop table tb
gocreate table tb
(
a varchar(10),
b varchar(10)
)insert into tb(a,b) values('aa', '0003')
insert into tb(a,b) values('aa', '0004')
insert into tb(a,b) values('aa', '0005')
insert into tb(a,b) values('bb', '3112')
insert into tb(a,b) values('bb', '4221')
insert into tb(a,b) values('bb', '0012')select * from tb b
where b=(select top 1 b from tb where a=b.a)drop table tba b
---------- ----------
aa 0003
bb 3112(所影响的行数为 2 行)
insert into @t
select 'aa','0003'
union all select 'aa','0004'
union all select 'aa','0005'
union all select 'bb','3112'
union all select 'bb','4221'
union all select 'bb','0012'select distinct name,code=(select top 1 code from @t where name=t.name) from @t t
所影响的行数为 6 行)name code
---------- ----------
aa 0003
bb 3112(所影响的行数为 2 行)