久久久久久久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ù)類型?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在創(chuàng)建一個(gè)論壇,所以我創(chuàng)建了一個(gè)包含帖子的表格.其中一個(gè)字段是 Body,類型為 XML.現(xiàn)在我想創(chuàng)建一個(gè)查詢,返回所有帖子和每個(gè)帖子的子項(xiàng)數(shù)量.我正在使用聚合函數(shù)執(zhí)行此操作.當(dāng)我使用聚合函數(shù)時(shí),我需要使用一個(gè)組.當(dāng)我使用 group by 中的字段時(shí),會(huì)出現(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 運(yùn)算符.

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

我該如何解決這個(gè)問題?

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 中進(jìn)行聚合,然后加入該聚合

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ù)類型?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個(gè)子標(biāo)記轉(zhuǎn)換為具有多個(gè)分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個(gè)表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計(jì)算值創(chuàng)建計(jì)算值)
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?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對(duì)?) - IT屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(hào)(問題和答案的組合))
主站蜘蛛池模板: 国产福利在线免费观看 | 日韩视频a| 国产一级网站 | 激情国产在线 | 91精品久久久久久久99 | 999久久久久久久久6666 | 亚洲国产精品自拍 | 亚洲免费在线观看 | 精品国产乱码久久久久久丨区2区 | 午夜资源 | 亚洲精品一区二区三区在线观看 | 麻豆久久久9性大片 | 国产精品大片 | 久草新在线 | 国产91丝袜在线播放 | 欧美久久久久久 | 亚洲一区二区三区在线播放 | 日韩最新网址 | 国产一二区免费视频 | 欧美日韩在线观看一区 | 久久99久久久久 | 一级做a爰片性色毛片16 | 91精品国产一区二区 | 亚洲综合五月天婷婷 | 日韩成人一区 | 亚洲一区中文 | 91久久北条麻妃一区二区三区 | 看一级毛片视频 | 国产成人精品一区二区三区 | 成人免费视频网址 | 成人黄色三级毛片 | 国产精品一区二区视频 | 免费在线a视频 | 99久久成人 | 爱爱视频在线观看 | 国产欧美精品一区二区 | 亚洲国产欧美日韩 | 手机在线观看av | 中文字幕在线第一页 | 中文字幕韩在线第一页 | 中文字幕亚洲精品 |