标题:VFP中使用DELETE语句无法删除问题
只看楼主
xiang0220
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2021-8-30
结帖率:100%
已结贴  问题点数:20 回复次数:5 
VFP中使用DELETE语句无法删除问题


题目要求是把选修刘老师课程的女同学选课元组全部删去。

DELETE FROM SC2 WHERE Cn IN(SELECT Cn FROM C2 WHERE TEACHER LIKE '刘%') AND Sn IN(SELECT Sn FROM S2 WHERE SEX='女')

我使用了这个语句,但是只删除了后面半句话,这是什么原因?

麻烦大佬帮我看一下
搜索更多相关主题的帖子: DELETE FROM 语句 删除 WHERE 
2021-08-30 11:03
mywisdom88
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:190
帖 子:3125
专家分:8340
注 册:2015-3-25
得分:10 
create table c:\s2(sn c(5),sname c(10),age i,sex c(4))
insert into s2(sn,sname,age,sex) values ('95001','李勇',20,'男')
insert into s2(sn,sname,age,sex) values ('95002','刘晨',19,'女')
insert into s2(sn,sname,age,sex) values ('95003','王敏',18,'女')
insert into s2(sn,sname,age,sex) values ('95004','李立',19,'男')

create table c:\c2(cn i,cname c(20),teacher c(10))
insert into c2(cn,cname,teacher) values (1,'数据库','李红军')
insert into c2(cn,cname,teacher) values (2,'数学','刘任仁')
insert into c2(cn,cname,teacher) values (3,'信息系统','何丽')
insert into c2(cn,cname,teacher) values (4,'操作系统','赵军强')
insert into c2(cn,cname,teacher) values (5,'数据结构','贾振江')
insert into c2(cn,cname,teacher) values (6,'数据处理','张毛毛')
insert into c2(cn,cname,teacher) values (7,'C语言','李超')
insert into c2(cn,cname,teacher) values (8,'VC++','宝宝')


create table c:\sc2(sn c(5),cn i,grade n(5,2))
insert into sc2(sn,cn,grade) values ('95001',1,96)
insert into sc2(sn,cn,grade) values ('95001',2,85)
insert into sc2(sn,cn,grade) values ('95001',3,56)
insert into sc2(sn,cn,grade) values ('95002',2,94)
insert into sc2(sn,cn,grade) values ('95002',3,88)
insert into sc2(sn,cn,grade) values ('95002',1,60)
insert into sc2(sn,cn,grade) values ('95001',4,58)
insert into sc2(sn,cn,grade) values ('95001',5,79)
insert into sc2(sn,cn,grade) values ('95002',6,66)
insert into sc2(sn,cn,grade) values ('95003',1,88)
insert into sc2(sn,cn,grade) values ('95003',3,59)
insert into sc2(sn,cn,grade) values ('95003',6,63)
insert into sc2(sn,cn,grade) values ('95004',3,93)
insert into sc2(sn,cn,grade) values ('95004',6,89)

*!* 题目要求是把选修刘老师课程的女同学选课元组全部删去

*!* 要删除合符的记录,你就要会查出那些些记录符合,有2种常见写法
*!* 方法1
SELECT sc2.* FROM sc2,(SELECT cn FROM c2 WHERE teacher='刘任仁') t1,(SELECT sn FROM s2 WHERE sex='女') t2 WHERE AND sc2.sn=t2.sn

*!* 方法2
SELECT sc2.* FROM sc2 ;
INNER JOIN (SELECT cn FROM c2 WHERE teacher='刘任仁')t1 ON ;
INNER JOIN (SELECT sn FROM s2 WHERE sex='女')t2 ON sc2.sn=t2.sn

*!* 删除1
DELETE sc2 from sc2,(SELECT cn FROM c2 WHERE teacher='刘任仁') t1,(SELECT sn FROM s2 WHERE sex='女') t2 WHERE AND sc2.sn=t2.sn

*!* 删除2
DELETE sc2 from sc2;
INNER JOIN (SELECT cn FROM c2 WHERE teacher='刘任仁')t1 ON ;
INNER JOIN (SELECT sn FROM s2 WHERE sex='女')t2 ON sc2.sn=t2.sn
SELECT sc2
BROWSE



2021-08-30 12:57
mywisdom88
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:190
帖 子:3125
专家分:8340
注 册:2015-3-25
得分:0 
符合条件的,只有1个
SN=95002 && 女人
CN=2 && 刘老师


2021-08-30 13:00
wengjl
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:108
帖 子:2175
专家分:3785
注 册:2007-4-27
得分:10 
用了DELE 再PACK 就删除干净了

只求每天有一丁点儿的进步就可以了
2021-08-30 13:18
xiang0220
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2021-8-30
得分:0 
回复 2楼 mywisdom88
为啥我这边写完这一串,回车后什么也不显示呢
DELETE sc2 from sc2,(SELECT cn FROM c2 WHERE teacher='刘任仁') t1,(SELECT sn FROM s2 WHERE sex='女') t2 WHERE AND sc2.sn=t2.sn
2021-08-30 14:19
mywisdom88
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:190
帖 子:3125
专家分:8340
注 册:2015-3-25
得分:0 
删除,是不显示的
要显示
select sc2
brow
2021-08-30 14:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-506705-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.384950 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved