久久久久久久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  

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

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

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-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ù)前一行內的計算值創(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)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 男人天堂av网| 国产精品99精品久久免费 | 中文字幕亚洲视频 | 天堂中文av | 偷偷操不一样 | 日韩精品极品视频在线观看免费 | 亚洲精品免费看 | 在线播放国产精品 | 中文字幕免费在线观看 | 亚洲区一区二 | 日韩一区精品 | 国产精品成人国产乱 | 国产午夜激情 | www.17c.com喷水少妇 | 中文字幕在线观看一区二区三区 | 青青青草视频在线观看 | 懂色av一区二区夜夜嗨 | 久久免费国产 | 在线一区 | 亚洲一级片 | 亚洲激情综合网 | 中文字幕第三页 | 午夜精品在线观看 | 日韩av在线免费 | 亚洲激情视频在线观看 | 宅男噜噜噜66一区二区 | 黄色成人小视频 | 亚洲精品福利 | 亚洲视频不卡 | 欧美精品综合 | 日韩中文字幕视频 | 亚洲激情网| 一级黄视频 | 久久精品国产77777蜜臀 | 亚洲精品一二三四 | 久久久精品一区二区三区 | 亚洲小视频 | 青青草av | av一区二区在线观看 | 欧美久久久久久久 | 免费看91|