求sql语句
a表(人) b表(水果)
aid name bid name
1 a 1 苹果
2 b 2 梨
3 c 3 橙
4 d 4 香蕉
c表
cid aid bid
1 1 1
2 1 3
3 1 4
4 2 3
5 2 4 问题:根据bid求出aid(如:bid=3 and bid=4 那么可以得到aid=1,aid=2,aid=4)
6 3 2 就是说根据条件给出的水果类别.来求出买了这些水果的人.
7 4 1
8 4 2 急~~~~~~~~~~~~~~~~~~~~~急~~~~~~~~~~~~~~~~~~~~~急~~~~~~~~~~~~~~~~~~~~~
9 4 3
10 4 4
[b]问题补充:[/b]
都不对啊.!!急啊!!!!!!!!!!!!!!!!!
[b]问题补充:[/b]
再说一下
如果买了bid=3和bid=4的人
那么aid就应该是1,2,4
知道了吗.并且不出现重复
select distinct(aid) from C where aid in (select aid from C where bid=3) and aid in (select aid from C where bid=4)
买了 橙子和香蕉的人的名字:
select name from a where aid in(select distinct(aid) from c where bid = 3 or bid = 4)
select name from a ,b,c where a.id=c.aid and b.id = c.bid and b.id=? or b.id= ?
后面的“b.id=?”具体要求填写
select distinct(aid) from c where bid = 3 or bid = 4
这样足矣