久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 GROUP BY 子句中添加 XML 數(shù)據(jù)類型?

How to add XML data type in a GROUP BY clause?(如何在 GROUP BY 子句中添加 XML 數(shù)據(jù)類型?)
本文介紹了如何在 GROUP BY 子句中添加 XML 數(shù)據(jù)類型?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在創(chuàng)建一個論壇,所以我創(chuàng)建了一個包含帖子的表格.其中一個字段是 Body,類型為 XML.現(xiàn)在我想創(chuàng)建一個查詢,返回所有帖子和每個帖子的子項數(shù)量.我正在使用聚合函數(shù)執(zhí)行此操作.當我使用聚合函數(shù)時,我需要使用一個組.當我使用 group by 中的字段時,會出現(xiàn)以下異常:

I'm creating a forum, so I have created a table with posts. One of the fields is a Body with of the type XML. Now I would like to create a query that returns all the posts and the number of children of every post. I'm doing this with an aggregate function. I need to use a group by when I'm using aggregate function. When I use the field in the group by, I'll get the following exception:

XML 數(shù)據(jù)類型無法比較或排序,除非使用IS NULL 運算符.

The XML data type cannot be compared or sorted, except when using the IS NULL operator.

我該如何解決這個問題?

How can I solve this?

我的查詢是:

SELECT 
    Post.PostId, Post.[Body], Count(Children.PostId)
FROM  
    dbo.Post Post, 
    dbo.Post Children 
WHERE
    Children.ParentId = Post.PostId
GROUP BY
    Post.PostId, 
    Post.[Body]

推薦答案

您可以在 CTE 中進行聚合,然后加入該聚合

You can do the aggregation in a CTE then join onto that

WITH Children(Cnt, ParentId)
     AS (SELECT COUNT(*),
                ParentId
         FROM   dbo.Post
         GROUP  BY ParentId)
SELECT P.PostId,
       P.[Body],
       ISNULL(Cnt, 0) AS Cnt
FROM   dbo.Post P
       LEFT JOIN Children /*To include childless posts*/
         ON Children.ParentId = P.PostId
ORDER  BY P.PostId  

這篇關(guān)于如何在 GROUP BY 子句中添加 XML 數(shù)據(jù)類型?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉(zhuǎn)換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計算值創(chuàng)建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 337p日韩| 天天插天天操 | 成人国产精品久久 | 日韩在线中文字幕 | 91久久久久久久久 | 国产精品区二区三区日本 | 亚洲一区二区在线播放 | 精品毛片视频 | 日韩中文字幕一区二区 | caoporn国产精品免费公开 | 日本午夜一区 | 亚洲人在线 | 精品99在线 | 国产欧美久久一区二区三区 | 欧美精品一区二区三区在线播放 | 日本超碰 | 国产精品久久久久久久午夜片 | 精品国产乱码久久久久久1区2区 | 国产精品免费在线 | 国产精品伦一区二区三级视频 | caoporn国产精品免费公开 | 国产精品久久久久久久久久免费看 | 伊人久久大香线 | 欧美亚洲在线视频 | 一区二区三区四区免费观看 | 国产最新网址 | 爱草视频 | 久久精品国产一区二区三区 | 中文无吗 | 国产成人精品视频 | 成人一区二区三区在线观看 | 中文字幕高清在线 | 精品福利视频一区二区三区 | 国产99久久久久 | 国产精品福利在线观看 | 中文字幕中文字幕 | 久久网亚洲 | 欧美999| 嫩草网 | 久久综合伊人一区二区三 | 国产精品一区二区在线 |