您的位置:首页 > 其它

关于联合查询一个例子

2012-11-22 16:11 85 查看
ec_skill表中:id_weapon_type字段 有五种值(0001,0010,0100,1000,1111) id字段

ec_role表中:occupation字段 有四种值(0,1,2,3,) id字段

ec_role_skill表中:role_id字段 skill_id字段

role_id字段存储的是ec_role表中的id字段的值

skill_id字段存储的是ec_skill表中的id字段的值

0001只能对应0,

0010只能对应1,

0100只能对应2,

1000只能对应3,

1111可以对应0、1、2、3

想查询有没有不是这么对应的数据

select a.role_id,a.skill_id,b.id,b.id_weapon_type,c.id,c.occupation

from ec_role_skill a,ec_skill b,ec_role c

where a.role_id=c.id and a.skill_id=b.id

and b.id_weapon_type<>'1111' and not ((b.id_weapon_type='0001' and c.occupation=0) or (b.id_weapon_type='0010' and c.occupation=1) or (b.id_weapon_type='0100' and c.occupation=2) or (b.id_weapon_type='1000' and c.occupation=3) ) order by

id_weapon_type
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: