集合的问题
dbf1是A班全体同学,dbf2是书法兴趣班全体同学,书法兴趣班来自A班、B班、C班,现在要将A班没参加书法兴趣班的同学归到另一个表dbf3中,代码要怎样实现 ?select 中的union好象是并集,交集要用哪个命令 ?
请试一试,是这个意思吗?
CREATE dbf T1(id n(3),name c(12),class n(3))
INSERT INTO T1 values(1,"AAA",1)
INSERT INTO T1 values(2,"AAB",1)
INSERT INTO T1 values(3,"AAC",1)
INSERT INTO T1 values(4,"AAD",1)
INSERT INTO T1 values(5,"AAE",1)
CREATE dbf T2(id n(3),name c(12),class n(3))
INSERT INTO T2 values(1,"AAA",1)
INSERT INTO T2 values(2,"AAB",1)
INSERT INTO T2 values(3,"AAF",2)
INSERT INTO T2 values(4,"AAD",3)
INSERT INTO T2 values(5,"AAE",3)
SELECT T1.* FROM T1 WHERE T1.name + ALLTRIM(STR(T1.class)) NOT IN (SELECT T2.name + ALLTRIM(STR(T2.class)) FROM T2)