一个表中有如下记录:
id content bak
1 a, b,
2 a,b, a,
3 a,b,c, c,
.
.
.
请问如何用一条SQL语句列出content字段中包含id=1的bak的值的id.
假如id=1则返回:
id
2
3
假如id=2则返回:
id
1
2
3
假如id=3则返回:
id
3
如此类推……
...全文
3121打赏收藏
求SQL语句,有兴趣的进来看看。
一个表中有如下记录: id content bak 1 a, b, 2 a,b, a, 3 a,b,c, c, . . . 请问如何用一条SQL语句列出content字段中包含id=1的bak的值的id. 假如id=1则返回: id 2 3 假如id=2则返回: id 1 2 3 假如id=3则返回: id 3 如此类推……
select id from test where charindex((select bak from test where id = 1),content)>0
select id from test where charindex((select bak from test where id = 2),content)>0
select id from test where charindex((select bak from test where id = 3),content)>0
aa=request("id")
sql="select bak from table where id='"&aa&"' "
set rs =cnn.execute(sql)
bb=rs("bak")
sqlnew="select id from table where content like '%"&bb&"%' "
==============================================================
最后一句改一下:
sqlnew="select count(*) as vam from table where content like '%"&bb&"%' "
aa=request("id")
sql="select bak from table where id='"&aa&"' "
set rs =cnn.execute(sql)
bb=rs("bak")
sqlnew="select id from table where content like '%"&bb&"%' "