table aa
(
id int ,--自动编号
userid int ,--用户id
prcid int ,--产品id
str varchar(2000)---数字字符串
)
id userid str
1 2 '1,2,3,4,5'
2 3 ',23,4,5'
3 4 '1,2,5,4'
已经获取在str列中最小唯一值是3
如何根据3获取3所在列的id值或userid值??
结果是什么
没明白什么意思
SQL code:
select userid
from tb
where charindex(',3,',','+str+',')>0
group by userid
SQL code:
select * from tb where charindex(',3,',','+str+',')>0
SQL code:
create table aa
(
id int ,--自动编号
userid int ,--用户id
prcid int ,--产品id
str varchar(2000)---数字字符串
)
insert aa (id ,userid ,str)
select 1 ,2, '1,2,3,4,5' union all
select 2, 3, '23,4,5' union all
select 3, 4, '1,2,5,4'
with cte as(
select
a.id,userid,b.value
from
(select id,userid,str=convert(xml,'<root><row>'+replace(str,',','</row><row>')+'</row></root>') from aa)a
outer apply
(select value=T.C.value('.','nvarchar(100)') from a.str.nodes('/root/row')T(C))b)
select top 1 * from (
selec
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......