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

如何在 GROUP BY 子句中添加 XML 數據類型?

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

問題描述

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

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 數據類型無法比較或排序,除非使用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 數據類型?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

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?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
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屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 中文字幕第一页在线 | 久久国产综合 | 成人免费大片黄在线播放 | 色约约视频 | 国产在线一区二区三区 | 亚洲欧美日韩一区二区 | 日韩在线播放第一页 | 亚洲一区二区黄 | 日韩av在线一区二区 | 一区在线观看 | 亚洲日本一区二区三区四区 | 99精彩视频 | 国产亚洲一区二区精品 | 在线成人av | 欧美精品一区二区免费 | 欧美成人一区二区三区 | 亚洲 欧美 另类 综合 偷拍 | 羞羞的视频免费观看 | 亚洲一区中文字幕 | 日韩高清av| 高清国产一区二区 | 亚洲综合区 | 一本一道久久a久久精品综合蜜臀 | 国产精品久久九九 | 日本电影韩国电影免费观看 | 亚洲91av| 成人av一区二区在线观看 | 狠狠涩 | 国产区免费视频 | 免费a v网站 | 国产日韩一区二区三免费 | 国产精品国产三级国产aⅴ浪潮 | 综合色站导航 | 人人叉| 亚洲一区在线日韩在线深爱 | 国产日韩视频 | 91免费视频观看 | 国产精品v| 日韩精品一区二区三区在线观看 | 成人欧美日韩一区二区三区 | 伊伊综合网 |