我是第一次学习 XQuery,但在使用特定查询时遇到了麻烦。
找出生产至少两台速度至少为 2.00 的 PC 的 Maker 的名字。
我已经得到了查询的 Speed<=2.00 部分,但我不太清楚如何按出现次数对其进行分组。
尝试:(不输出任何内容)
let $doc := doc("PC.xml")
for $x in $doc/Products/Maker/PC
where $x/Speed>=2.00 and count($x)>=2
return $x/../@name
PC.xml:
<Products>
<Maker name = "A">
<PC model = "1001" price = "2114">
<Speed>2.66</Speed>
<RAM>1024</RAM>
<HardDisk>250</HardDisk>
</PC>
<PC model = "1002" price = "995">
<Speed>2.10</Speed>
<RAM>512</RAM>
<HardDisk>250</HardDisk>
</PC>
<Laptop model = "2004" price = "1150">
<Speed>2.00</Speed>
<RAM>512</RAM>
<HardDisk>60</HardDisk>
<Screen>13.3</Screen>
</Laptop>
<Laptop model = "2005" price = "2500">
<Speed>2.16</Speed>
<RAM>1024</RAM>
<HardDisk>120</HardDisk>
<Screen>17.0</Screen>
</Laptop>
</Maker>
<Maker name = "E">
<PC model = "1011" price = "959">
<Speed>1.86</Speed>
<RAM>2048</RAM>
<HardDisk>160</HardDisk>
</PC>
<PC model = "1012" price = "649">
<Speed>2.80</Speed>
<RAM>1024</RAM>
<HardDisk>160</HardDisk>
</PC>
<Laptop model = "2001" price = "3673">
<Speed>2.00</Speed>
<RAM>2048</RAM>
<HardDisk>240</HardDisk>
<Screen>20.1</Screen>
</Laptop>
<Printer model = "3002" price = "239">
<Color>false</Color>
<Type>laser</Type>
</Printer>
</Maker>
<Maker name = "H">
<Printer model = "3006" price = "100">
<Color>true</Color>
<Type>ink--jet</Type>
</Printer>
<Printer model = "3007" price = "200">
<Color>true</Color>
<Type>laser</Type>
</Printer>
</Maker>
</Products>