我知道这里高手云集,请高手赐教!
有一张普通的表里面有一列 是数字 能用
select max(maxrating) from Rating
找出最大的
现在我将这张表的数据制作成xml文档,导入一个xml列
insert into RatingXML (xmlRating)
select * from openrowset (
bulk 'C:\Users\LiuKe\Desktop\XML_F52E2B62.txt ',single_blob) as x;
想找到最大的值该怎么办?
我试图这样做 可是失败了
select xmlRating.query ( for $c/maxrating in '/root/Rating/maxrating'
where $c/maxrating = max('/root/Rating/maxrating') return $c) as result
from RatingXML
Msg 156, Level 15, State 1, Line 138
Incorrect syntax near the keyword 'for'.
Msg 126, Level 15, State 1, Line 139
Invalid pseudocolumn "$c".
[解决办法]
select o.value('maxrating[1]','varchar(10)') 'maxrating'
from RatingXML a
cross apply xmlRating.nodes('/root/Rating') x(o)
/*
maxrating
----------
0.41
0.37
0.94
0.73
0.60
0.99
(6 row(s) affected)
*/
select max(maxrating) 'max_maxrating'
from
(select o.value('maxrating[1]','varchar(10)') 'maxrating'
from RatingXML a
cross apply xmlRating.nodes('/root/Rating') x(o)) t
/*
max_maxrating
-------------
0.99
(1 row(s) affected)
*/