zoukankan      html  css  js  c++  java
  • For XML Path

    上For XML Path要使用 
    创建的表数据如图:

    先看下for xml path的初始使用方法:select ClassID,Sex,Age,Name from #PersonInfo for xml path('PersonInfo') 
     从名字就看能够看出使用方法。for xml  !!!

    在使用过程中感觉一般是恶group by 一起用的。举比例如以下:
    --统计每一个班中超过22岁的男同学信息
    select ClassID,COUNT(1) as '超过22岁个数',
    (select Name+',' from #PersonInfo where ClassID=p.ClassID for xml path ('')) as '姓名集合'
    from #PersonInfo p where Sex='男' and Age>22 group by ClassID order by ClassID
    select ClassID,Age,COUNT(1) as '超过22岁个数',
    (select Name+'。' from #PersonInfo where ClassID=p.ClassID and Age=p.Age for xml path ('')) as '姓名集合'
    from #PersonInfo p where Sex='男' and Age>22 group by ClassID,Age order by ClassID
    select ClassID,Age,COUNT(1) as '超过22岁个数',
    (select Name+'。' from #PersonInfo where ClassID=p.ClassID and Age=p.Age for xml path ('')) as '姓名集合'
    from #PersonInfo p where Sex='男' group by ClassID,Age having Age>22 order by ClassID

    结果例如以下:

    感觉having有用没有想象中那么大。只有在group by使用后。但聚合函数是有用的,只有大。或直接写信where以后你可以。
    加:收集的通过最后面的逗号命名stuff功能摆脱。
  • 相关阅读:
    UVA11082 矩阵展开,最大流
    UVA11082 矩阵展开,最大流
    hdu5855二分+最大流
    hdu5855二分+最大流
    高斯消元 hdu5833,hdu3364,hihocoder1195
    高斯消元 hdu5833,hdu3364,hihocoder1195
    傅里叶分析之掐死教程
    傅里叶分析之掐死教程
    php字符串大小写转换
    php strip_tags() 函数去除 HTML、XML 以及 PHP 的标签。
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5022020.html
Copyright © 2011-2022 走看看