SQL XQuery COUNT函数
本实例是演示SQL查询中XQuery使用COUNT函数。
DECLARE @xml XML = '
<Devs>
<lang name="VB.NET"/>
<lang name="C#.NET"/>
<lang name="Java" />
<lang name="Javascript" />
<lang name="ASP.NET" />
</Devs>
'
SELECT COUNT(*) AS [Totals] FROM @xml.nodes('/Devs') L(n)
SELECT COUNT(*) AS [Totals] FROM @xml.nodes('/Devs/lang') L(n)
<Devs>
<lang name="VB.NET"/>
<lang name="C#.NET"/>
<lang name="Java" />
<lang name="Javascript" />
<lang name="ASP.NET" />
</Devs>
'
SELECT COUNT(*) AS [Totals] FROM @xml.nodes('/Devs') L(n)
SELECT COUNT(*) AS [Totals] FROM @xml.nodes('/Devs/lang') L(n)
两条SQL SELECT执行结果: