mysql - XQuery: How to check if two attributes have the same value? -


suppose have 2 elements following:

(teacher name='john' age='25') , (student name='john' age='30)

and want find out students have same name 1 of teachers older teacher.

here have far:

for $teacher in //$teacher     $teacher/@name = //$student/@name      return     if (  $teacher/@age < //$student/@age)            ($teacher/@name)     else() 

it's not producing right results , have no idea why. me out please?

so, first problem xquery syntactically incorrect. starting dollar sign $ indicates variable, whereas // path step. combining variable , path step did //$teacher incorrect. hence, compiler should complain that.

the next problem logic flawed. want students, iterate on teachers.

additionally, approach fail, because students set of students, if search $students/@age set of all ages. hence, if twice (for attribute such @name, not guaranteed name , age belong same person.

so, following xquery should work , return expected results:

$students/student[exists(   let $s := .   $t in $teachers[@name = $s/@name , @age < $s/@age]   return $s )] 

this way, students, there @ least 1 teacher same name , younger age.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

qt - How to embed QML toolbar and menubar into QMainWindow -