SQL语句(100分)

  • 主题发起人 主题发起人 linjie0628
  • 开始时间 开始时间
L

linjie0628

Unregistered / Unconfirmed
GUEST, unregistred user!
有两个表TB1 TB2 <br><br>我要删除掉TB1的数据<br><br>ID &nbsp; &nbsp; &nbsp;SB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>1 &nbsp; &nbsp; &nbsp; AAA<br>2 &nbsp; &nbsp; &nbsp; BBB<br>3 &nbsp; &nbsp; &nbsp; CCC<br>4 &nbsp; &nbsp; &nbsp; DDD<br>5 &nbsp; &nbsp; &nbsp; EEE<br><br>TB2<br><br>ID &nbsp; &nbsp; &nbsp;SB &nbsp; &nbsp; AB<br>1 &nbsp; &nbsp; &nbsp; AAA &nbsp; &nbsp;QQQ<br>2 &nbsp; &nbsp; &nbsp; BBB &nbsp; &nbsp;QQQ<br>3 &nbsp; &nbsp; &nbsp; CCC &nbsp; &nbsp;111<br>4 &nbsp; &nbsp; &nbsp; DDD &nbsp; &nbsp;234<br>5 &nbsp; &nbsp; &nbsp; EEE &nbsp; &nbsp;123<br><br>TB1效果是 &nbsp; &nbsp;TB2不变<br>ID &nbsp; &nbsp; &nbsp;SB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>1 &nbsp; &nbsp; &nbsp; AAA &nbsp;---删除<br>2 &nbsp; &nbsp; &nbsp; BBB &nbsp;---删除<br>3 &nbsp; &nbsp; &nbsp; CCC<br>4 &nbsp; &nbsp; &nbsp; DDD<br>5 &nbsp; &nbsp; &nbsp; EEE
 
delete from tb1 where tb1.sb=tb2.sb and tb2.ab='QQQ'
 
create table TB1 (id int, sb varchar(10))<br>create table TB2 (id int, sb varchar(10),ab varchar(10))<br>insert into TB1 values(1,'AAA')<br>insert into TB1 values(2,'BBB')<br>insert into TB1 values(3,'CCC')<br>insert into TB1 values(4,'DDD')<br>insert into TB1 values(5,'EEE')<br>insert into TB2 values(1,'AAA','QQQ')<br>insert into TB2 values(2,'BBB','QQQ')<br>insert into TB2 values(3,'CCC','111')<br>insert into TB2 values(4,'DDD','234')<br>insert into TB2 values(5,'EEE','123')<br><br>delete TB1 where sb in (select distinct sb from TB2 where ab='QQQ' )<br><br>select * from TB1<br><br><br><br>drop table TB1<br>drop table TB2
 
create table TB1 (id int, sb varchar(10))<br>create table TB2 (id int, sb varchar(10),ab varchar(10))<br>insert into TB1 values(1,'AAA')<br>insert into TB1 values(2,'BBB')<br>insert into TB1 values(3,'CCC')<br>insert into TB1 values(4,'DDD')<br>insert into TB1 values(5,'EEE')<br>insert into TB2 values(1,'AAA','QQQ')<br>insert into TB2 values(2,'BBB','QQQ')<br>insert into TB2 values(3,'CCC','111')<br>insert into TB2 values(4,'DDD','234')<br>insert into TB2 values(5,'EEE','123')<br><br><br>--delete TB1 where sb in (select distinct sb from TB2 where ab='QQQ' )<br><br>--写法2 <br>delete TB1 from TB1,TB2 where &nbsp;TB1.sb=TB2.sb and &nbsp; TB2.ab='QQQ' <br>select * from TB1<br><br><br><br>drop table TB1<br>drop table TB2
 
谢谢,问题已经解决了
 

Similar threads

I
回复
0
查看
728
import
I
I
回复
0
查看
425
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部