sqlserver 用FOR XML PATH('')多行并成一列

SELECT B.order_id,order_status_list FROM (
SELECT order_id,
(SELECT CAST(order_status as varchar)+‘,‘ FROM zmaction
WHERE order_id=A.order_id
order by order_status desc
FOR XML PATH(‘‘)) AS order_status_list
FROM zmaction A
GROUP BY order_id
) B
where
order_status_list like ‘%8,3,2,0,%‘
or
order_status_list like‘%8,3,2,2,0,%‘
or
order_status_list like ‘%,1,%‘
or
order_status_list like ‘%8,4,%‘
or
order_status_list like ‘%2,0,%‘

 

---将设置order_status 为一行order_status_list

SELECT CAST(order_status as varchar)+‘,‘ FROM zmaction
WHERE order_id=A.order_id
order by order_status desc
FOR XML PATH(‘‘)) AS order_status_list
FROM zmaction A

sqlserver 用FOR XML PATH('')多行并成一列

上一篇:Python流行ORM框架sqlalchemy


下一篇:数据库生成序列号,无论那个数据库 都有这几句话