[英]Using xquery FLWOR expressions to find multiple “where” restrictions
I am trying to find employees who work on projects located in Houston but the department the project is housed in is not located in Houston. 我正在努力找到在休斯顿工作的员工,但项目所在的部门并不在休斯顿。 I was trying to model the expression after this example of FLWOR expressions but the query doesn't return anything and it should return results.
我试图在FLWOR表达式的这个示例之后对表达式进行建模,但是查询没有返回任何内容,它应该返回结果。
edit: Here is the input . 编辑:这是输入 。
xquery
let $doc := doc("~path/company.xml")
for $e in $doc//employee,
$d in $doc//department,
$p in $doc//projects
where $d/locations[location!="Houston"]
and $p/project[plocations="Houston"]
return <e>{$e/fname}{$e/lname}{$e/address}</e>
/
One for
clause is enough; 一个
for
子句就足够了; otherwise, you'll iterate over all employees several times: 否则,你会多次迭代所有员工:
let $doc := doc(...)
for $e in $doc//employee
let $p := $doc//project[@pnumber = $e/projects/worksOn/@pno]
where $p[plocation = 'Houston']
and $doc//department[@dno = $p/@controllingDepartment]
[not(locations/location = 'Houston')]
return <e>{ $e/fname }{ $e/lname }{ $e/address }</e>
A single XPath 2.0 expression can select all wanted employees: 单个XPath 2.0表达式可以选择所有想要的员工:
/*/employees
/*[projects/*/@pno
=
/*/projects/*
[plocation eq 'Houston'
and
boolean
(for $dn in @controllingDepartment
return
/*/departments/*
[@dno eq $dn
and
not(locations/location
=
'Houston'
)
]
)
]/@pnumber
]
Typo: and $p/project[plocation="Houston"]
错字:
and $p/project[plocation="Houston"]
You had an "s" too much: was plocations
. 你有一个“s”太多了:是
plocations
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.