表里有个3个字段 A 、B 、C,我想先取出表里所有A的值,然后在A里在取出C的值。代码怎么实现呢,
A里面有C
B里面也有C
我只想取出A里的C。
select * from table where class='bwl' and groupname='666'
你是说取出a和c字段相等的记录?
select a, c from table where a = c
select a from table where a=(selec c from table ); 如果不行的话就把等号换成in.
字段值进行比较,用SQL的charindex函数,charindex(c,a)>0表示A字段值里包含了C字段的值
要是需要读取2次就插入2个临时表
select * into #table1 from table1 where class = 'bwl'
select * into #table2 from table1 where class = 'bwl' and groupname='666'
select * from #table1
select * from #table2
只读取一次就直接
select * from table where class='bwl' and groupname='666'