**************************** * XQuery * **************************** (Titles and author first name names of books whose title contains one of the author's first names) for $b in doc("BookstoreQ.xml")/Bookstore/Book where some $fn in $b/Authors/Author/First_Name satisfies contains($b/Title, $fn) return { $b/Title } { $b/Authors/Author/First_Name } (Now include only first names in book title) for $b in doc("BookstoreQ.xml")/Bookstore/Book where some $fn in $b/Authors/Author/First_Name satisfies contains($b/Title, $fn) return { $b/Title } { for $fn in $b/Authors/Author/First_Name where contains($b/Title, $fn) return $fn } (Books where every author's first name includes "J") for $b in doc("BookstoreQ.xml")/Bookstore/Book where every $fn in $b/Authors/Author/First_Name satisfies contains($fn, "J") return $b (This query finds the average book price) { Let $plist := doc("BookstoreQ.xml")/Bookstore/Book/@Price return avg($plist) } (Books whose price is below average) let $a := avg(doc("BookstoreQ.xml")/Bookstore/Book/@Price) for $b in doc("BookstoreQ.xml")/Bookstore/Book where $b/@Price < $a return { $b/Title } { $b/data(@Price) } (Order the book price) for $b in doc("BookstoreQ.xml")/Bookstore/Book order by xs:int($b/@Price) return { $b/Title } { $b/data(@Price) } (All last names - contains repeats) for $n in doc("BookstoreQ.xml")//Last_Name return $n (All last names - without repeats) for $n in distinct-values(doc("BookstoreQ.xml")//Last_Name) return { $n } (return pairs of books that share a author's last name) for $b1 in doc("BookstoreQ.xml")/Bookstore/Book for $b2 in doc("BookstoreQ.xml")/Bookstore/Book where $b1/Authors/Author/Last_Name = $b2/Authors/Author/Last_Name and $b1/Title < $b2/Title return { data($b1/Title) } { data($b2/Title) } (Invert data: Authors with the books they've written) { for $ln in distinct-values(doc("BookstoreQ.xml")//Author/Last_Name) for $fn in distinct-values(doc("BookstoreQ.xml")//Author[ Last_Name=$ln]/First_Name) return { $fn } { $ln } { for $b in doc("BookstoreQ.xml")/Bookstore/Book[ Authors/Author/Last_Name = $ln] return < $b/@ISBN } { $b/@Price } { $b/Title } **************************** * XQuery * **************************** ... (Book and magazine titles, relabled) (All books costing less than $90) (All books costing less than $90 and all the magazines) (copy entire data) (a more completed way of copying entire data, we further change ISBN to a sub-element, and convert Author to an attribute) (HTML Table of books costing less than $90, sorted by price)
Book Cost
(Expunge 'Jennifer', change 'Widom' to 'Ms. Widom') Ms. Widom (Same thing as the previous one) Ms. Widom