昨天设计了个模型。有一个表是这样设计的
create table tab_1
(
PCode Varchar(10) not null,
F_code Varchar(40),
pType Char(1),
PName Varchar(100)
)
里面有一条记录,是‘spcode’,‘Online’,‘role’,''1,2,3''
注意最后一个字段,字段里面是存的三个数据,用逗号隔开。
create table test_tjc(
sid Varchar(10),
sname Varchar(100),
svalue Varchar(30)
)
insert into test_tjc values(‘1','name1','value1' );
insert into test_tjc values( '2','name1','value1' );
insert into test_tjc values( '3','name1','value1' );想这样取出tab_1 中PName 是1或2或3的全部数据。
我是这样做的
select * from test_tjc where sid in(
select PName from tab_1 where PCode = 'spcode'
)
但是不对。请教该怎么样写
create table tab_1
(
PCode Varchar(10) not null,
F_code Varchar(40),
pType Char(1),
PName Varchar(100)
)
里面有一条记录,是‘spcode’,‘Online’,‘role’,''1,2,3''
注意最后一个字段,字段里面是存的三个数据,用逗号隔开。
create table test_tjc(
sid Varchar(10),
sname Varchar(100),
svalue Varchar(30)
)
insert into test_tjc values(‘1','name1','value1' );
insert into test_tjc values( '2','name1','value1' );
insert into test_tjc values( '3','name1','value1' );想这样取出tab_1 中PName 是1或2或3的全部数据。
我是这样做的
select * from test_tjc where sid in(
select PName from tab_1 where PCode = 'spcode'
)
但是不对。请教该怎么样写
where exists(select 1 from tab_1 b where instr(','||b.PName||',',','||a.sid||',')>0)