这个 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
相关问答:
从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式
XML code:
<folder state="unchecked" label="全部">
<folder state="unchecked&qu ......
如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP
参考:http://hi.baidu.com/toiota ......
我想查询出每天数据的最大的一个值。表的格式如下
表名: hisdata
字段 编号 值 状态 时间
Id value state dattime
101 32.3 0 ......
下面是XML初始文件内容
XML code:
<upd:Update xmlns:lar="http://schemas.microsoft.com/msus/2002/12/LogicalApplicabilityRules" xmlns:cmd="http://schemas.microsoft.com/msus/2002/12/Up ......
需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......