For Xml的用法
近期有个需求,就是要sql统计某客户当天共计下了多少订单,订单号是什么?所以想到了For Xml
For Xml基础的输出XML格式我这边就不多说了,主要介绍如何实现上述问题
代码:
SELECT name,
(SELECT code+',' FROM
(select name,code from order where 日期='2017-3-17' and 客户 like ('%%'))b
WHERE name=A.name
FOR XML PATH('')) AS sList
FROM
(select name,code from order where 日期='2017-3-17' and 客户 like ('%%'))A
GROUP BY name