才学sql,只知道union可以合并,不知道如何sql语句删除,我现在只实现了数值上的能够相减,不能得到表。请指教!谢谢select count(*) as 常住人口含学生 from 原始 where A102<>2 and A114=1
select count(*) as 学生 from 原始 where A102<>2 and A114=1 and A117=1 and A118>=5 and A113<2
select count(*) as 学生 from 原始 where A102<>2 and A114=1 and A117=1 and A118>=5 and A113<2
select count(*) as 常住人口含学生 from 原始 where A102<>2 and A114=1
select count(*) as 学生 from 原始 where A102<>2 and A114=1 and A117=1 and A118>=5 and A113<2
第一个查询包含第二个查询(因为第二个查询只是在第一个查询的基础上加了一些限制条件),我想得到一张新表,效果就是就是在第一个查询的基础上去掉第二个查询出来的行,sql语句的union可以实现两个表的相加,但是没有语句可以实现相减。想请高手指教一下。
INTERSECT(两个集合中都存在的数据)
--在2000中没有,要用not eexists
select * from 调查表 where A102<>2 and A114=1 and not exists(select * from 调查表 where A102<>2 and A114=1 and A117=1 and A118>=5 and A113<2)
--或者
select * from 调查表 where A102<>2 and A114=1
and 主键字段 not in
(select 主键字段 from 调查表 where a.主键字段=b.主键字段 and A102<>2 and A114=1 and A117=1 and A118>=5 and A113<2)
select * from 调查表 where A102<>2 and A114=1
and 主键字段 not in
(select 主键字段 from 调查表 where A102<>2 and A114=1 and A117=1 and A118>=5 and A113<2)
1、用exists,为什么会有调查表a,b
2、为什么要用主键,假如我这个表没有设置主键或者是双主键,又怎么实现呢
再次表示感谢!
and not exists(select * from 调查表 b
where a.主键字段1=b.主键字段1 and a.主键字段2=b.主键字段2...
and A102<>2 and A114=1 and A117=1 and A118>=5 and A113<2)ps:上下两个表必须关联进行比对,所以这样
select count(*) as 常住人口含学生
from 原始 where A102<>2 and A114=1
and not (A117=1 and A118>=5 and A113<2)
delete from exam372 a where EXISTS (select name from exam372_TEMP b where a.name=b.name)