易截截图软件、单文件、免安装、纯绿色、仅160KB

这个 sql删除语句怎么写? - MS-SQL Server / 基础类

SQL code:
declare @tb1 table(a varchar(20),b varchar(20))
insert into @tb1 select 'a101','b11121'
insert into @tb1 select 'a102','b00012'
select * from @tb1

declare @tb2 table(id int,c varchar(20))
insert into @tb2 select 1,'a101'
insert into @tb2 select 2,'b11121'
insert into @tb2 select 3,'a000'
insert into @tb2 select 4,'c1001'
select * from @tb2

我现在要把 @tb2 中c字段 在 @tb1 中有重复的数据删除,保留@tb2 中id 较小的

@tb1中 'a101',' b11121' 在同一行,
而@tb2 中c字段有
1 a101
2 b11121
3 a000
4 c1001

就删除第二行,最后得到结果
1 a101
3 a000
4 c1001

这个sql怎么写?

修改一下

SQL code:
declare @tb1 table(id int,a varchar(20),b varchar(20))
insert into @tb1 select 1,'a101','b11121'
insert into @tb1 select 2,'a102','b00012'
select * from @tb1

declare @tb2 table(id int,c varchar(20))
insert into @tb2 select 1,'a101'
insert into @tb2 select 2,'b11121'
insert into @tb2 select 3,'a000'
insert into @tb2 select 4,'c1001'
select * from @tb2

两表id都是唯一的

我现在要把 @tb2 中c字段 在 @tb1 中有重复的数据删除,保留@tb2 中id 较小的

@tb1中 'a101',' b11121' 在同一行,
而@tb2 中c字段有
1 a101
2 b11121
3 a000
4 c1001

就删除第二行,最后得到结果
1


相关问答:

csv文件转换成sql导入到数据库,没有数据为何?

执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......

SQL如何优化问题 - MS-SQL Server / 疑难问题

今天做了一个存储过程   环境是SQL2000数据库  
大致如下
建立临时表
定义员工游标
        循环员工(属于1个公司)  
        ......

求一SQL - MS-SQL Server / 基础类

tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......

请教SQLSERVER的两个问题 - MS-SQL Server / 疑难问题

1。怎样使xp_cmdshell能完整输出超过255个字符的字符串。
2。select 时,检索速度是与from后的 TABLE顺序有关,还是与where条件的顺序有关(TABLE数据多少 )
在系统属性设定里有个选项,可以修改单字段输出字数限制. ......

SQL语句问题 - MS-SQL Server / 疑难问题

请教高手:
 以下是数据库中的三条记录,英文为字段名称  
  id planname TaskBeginTime Status
329 2010年03 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号