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

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

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

問(wèn)題描述

我正在創(chuàng)建一個(gè)論壇,所以我創(chuàng)建了一個(gè)包含帖子的表格.其中一個(gè)字段是 Body,類(lèi)型為 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ù)類(lèi)型無(wú)法比較或排序,除非使用IS NULL 運(yùn)算符.

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

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

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

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(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屋-程序員軟件開(kāi)發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱(chēng)轉(zhuǎn)換為日期/月份編號(hào)(問(wèn)題和答案的組合))
主站蜘蛛池模板: 日韩在线欧美 | 伊人伊成久久人综合网站 | 日韩字幕一区 | 欧美激情精品久久久久 | 久久一区二区三区四区五区 | 久久精品亚洲 | 成人av在线网站 | 精品国产一级 | 国产精品视屏 | 成人伊人 | 欧美日韩在线高清 | 91免费在线看 | 色久影院 | 国产成人综合在线 | 91久久国产综合久久91精品网站 | 在线观看成人免费视频 | 久久精品中文 | 91精品国产91久久综合桃花 | 日韩在线h| av片在线观看网站 | 欧美日高清| av大片在线观看 | 亚洲精品天堂 | 国产九九九 | 色花av| 97视频免费 | 精品国产青草久久久久96 | 黄色网一级片 | 在线观看免费毛片 | 亚洲国产成人av好男人在线观看 | 一区二区三区高清在线观看 | 亚洲欧美综合精品另类天天更新 | 国产一区二区三区免费观看视频 | 日本三级日产三级国产三级 | 亚洲精品一区二三区不卡 | 国产91黄色 | 欧美一区二区 | 亚洲精品一区二三区不卡 | 二区久久| 喷水毛片 | 成人在线免费网站 |