在SQL中查询XML文档
我从正在处理的一个相当大的XML文件中截取了以下代码:在SQL中查询XML文档,xml,sql-server-2005,Xml,Sql Server 2005,我从正在处理的一个相当大的XML文件中截取了以下代码: <Product id="4161" removed="false"> <NativeReviewStatistics> <AverageRatingValues> <AverageRatingValue> <AverageRating>3.0</AverageRating>
<Product id="4161" removed="false">
<NativeReviewStatistics>
<AverageRatingValues>
<AverageRatingValue>
<AverageRating>3.0</AverageRating>
<RatingDimension>
<ExternalId>Quality</ExternalId>
<RatingRange>5</RatingRange>
</RatingDimension>
</AverageRatingValue>
<AverageRatingValue>
<AverageRating>4.0</AverageRating>
<RatingDimension>
<ExternalId>Value</ExternalId>
<RatingRange>5</RatingRange>
</RatingDimension>
</AverageRatingValue>
</AverageRatingValues>
</NativeReviewStatistics>
</Product>
但我有点困惑,不知该从这里走到哪里。有什么想法吗
SELECT
feed.product.value('@id[1]', 'INT') AS ProductId,
step3.data.value('ExternalId[1]', 'varchar(50)') AS ExternalId,
step2.data.value('AverageRating[1]', 'decimal(10,1)') AS AveRating,
step3.data.value('RatingRange[1]', 'int') AS RatingRange
FROM
@xmlData.nodes('/Feed/Product') feed ( product )
CROSS APPLY
feed.product.nodes('NativeReviewStatistics/AverageRatingValues/AverageRatingValue') step2(data)
CROSS APPLY
step2.data.nodes('RatingDimension') step3(data)
SELECT feed.product.value('@id[1]', 'INT') AS ProductId
FROM @xmlData.nodes('/Feed/Product') feed ( product )
SELECT
feed.product.value('@id[1]', 'INT') AS ProductId,
step3.data.value('ExternalId[1]', 'varchar(50)') AS ExternalId,
step2.data.value('AverageRating[1]', 'decimal(10,1)') AS AveRating,
step3.data.value('RatingRange[1]', 'int') AS RatingRange
FROM
@xmlData.nodes('/Feed/Product') feed ( product )
CROSS APPLY
feed.product.nodes('NativeReviewStatistics/AverageRatingValues/AverageRatingValue') step2(data)
CROSS APPLY
step2.data.nodes('RatingDimension') step3(data)