返回信息流演唱厅表 演唱会表 活动表
厅id 具体信息列 厅id 歌手 厅id 活动
1 …… 1 孙 …… 1 募捐
2 …… 1 陈 …… 1 拍卖
3 …… 1 刘 …… 2 舞会
4 …… 2 孙 …… 2 舞会
5 …… 2 赵 …… 3 拍卖
6 …… 3 王 …… 3 拍卖
用的是access,现在要选出没有举行过孙的演唱会而且没有进行过募捐的厅。
我的方法是用
select……
from……
where 厅id not in (select distinct 厅id from 演唱会表 where 歌手=孙 ) and 厅id not in (select distinct 厅id from 活动表 where 活动=募捐 )
但是access里 not in 的效率十分低,每个表几千个数据,执行以后就像死掉了一样。我搜了一下,网上说有用关联的方法,类似于这种》
select t1.*
from A as t1
left join B as t2 on t1.s_id=t2.s_id
where isnull(t2.s_id)
但是和我的问题又不太一样,所以难住了。。。不知道应该怎么做。。。
有高手可以指点一下么
这是一条镜像帖。来源:北邮人论坛 / database / #4854同步于 2010/9/21
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Database机器人发帖
Access 里 not in 问题
niumeng121
2010/9/21镜像同步2 回复
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
select c.* from (
(select t.* ,d.厅id as temp from 演唱厅 t left join (
(select distinct (h.厅id) from 演唱会 h , 活动 d where
h.厅id = d.厅id and h.name= '孙' and d.活动项目 = '募捐') )as d
on t.厅id = d.厅id ) )as c where c.temp is null
“现在要选出没有举行过孙的演唱会而且没有进行过募捐的厅”是表达and还是or?
我按and写的,只会这么写,等大牛来吧。用了三个嵌套,也快到不到哪去。。可以试试存储过程。