假如说有这样一个身份表人id  身份    22356 导演
22469 编剧
22356 演员
22356 制片人
22356 道具师
22389 作曲人
21598 演员
19568 导演
..... ....
..... ....在一个电影里一个人的身份可以是编剧可以是演员也可以是导演,
假如说我要找一个人同时是导演也是编剧也是演员 应该怎么写
我试了用select 人的id from 身份表
where 身份= '导演' and 身份 = '编剧' and 身份 = '演员'可是这样返回的0,什么都没的……请问要怎么样写才可以得出我想要的结果~谢谢!

解决方案 »

  1.   

    select 人的id from 身份表 t
    where 身份= '导演' 
    and exists (select 2 from 身份表 where 人的id=t.人的id and 身份= '编剧' )
    and exists (select 2 from 身份表 where 人的id=t.人的id and 身份= '演员' )
      

  2.   

    select distinct 人id from 身份表 a where exists(
    select 1 from 身份表 where a.人id=人id and 身份='导演')
    and 
    exists(
    select 1 from 身份表 where a.人id=人id and 身份='演员')
      
      

  3.   

    michel14 (michel14)
      '截至2012-10-27 05:04:54  用户结帖率0.00%  
    当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
    http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
    http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html8、如何给分和结贴?
    http://community.csdn.net/Help/HelpCenter.htm#结帖