选择sql xquery中所有记录的所有元素x的不同列表 [英] Select distinct list of all elements x of all records in sql xquery

查看:20
本文介绍了选择sql xquery中所有记录的所有元素x的不同列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的查询表达式:

SELECT distinct xmlCol.value('(//interest/@id)[1]','nvarchar(64)') FROM table1

返回所有记录的 first interest 元素的 id 列表.

Returns a list of id of first interest element of all records.

但是一个 xml 可能包含 多个 interest 元素.

But an xml may contains multiple interest elements.

那么,如何在 sql xquery 中获取所有记录的所有 interest 元素的不同列表?

So, how to get a distinct list of all interest elements of all records in sql xquery ?

推荐答案

select distinct T.N.value('.','nvarchar(64)')
from table1
  cross apply xmlCol.nodes('//interest/@id') as T(N)

这篇关于选择sql xquery中所有记录的所有元素x的不同列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆