34,576
社区成员
发帖
与我相关
我的任务
分享
create table t_a
(a_id int,
a_name varchar(10)
)
insert into t_a(a_id ,a_name)
select 1,'功能一'
union select 2,'功能二'
create table t_b
(b_id int,
b_name varchar(20),
b_content varchar(50))
insert into t_b(b_id,b_name,b_content)
select 1,'权限一','1,2'
create table t_c
(c_name varchar(10),
c_role int)
insert into t_c(c_name,c_role)
select '测试一',1
select a.* from t_a a,t_c c, t_b b
where charindex(','+ltrim(a.a_id)+',',','+ b.b_content+',' )>0
and c.c_role = b.b_id
/*
a_id a_name
----------- ----------
1 功能一
2 功能二
(所影响的行数为 2 行)
*/
select * from t_a
where a_id in (
select b.role_content from t_c c, t_b b
where c.c_role = b.b_id
)
select * from t_a aa where exists(
select 1 from t_c c, t_b b
where c.c_role = b.b_id and charindex(','+ltrim(a_id)+',',','+role_content+',')>0)