Skip to content

Commit f543e98

Browse files
committed
Database bookCatalogs completed
1 parent fbc1347 commit f543e98

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

arcade/databases/bookCatalogs.mysql

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
/*
3+
You have your very own library at home, and it's getting bigger and bigger with each passing month. You've decided to create a database in which to store information about your books, in the hope that it will help you remember which books you have in your library.
4+
5+
Information about the books in your library is stored in the table catalogs, which contains the following columns:
6+
7+
doc_id - the unique ID of the catalog;
8+
xml_doc - the catalog as an XML file in the following format:
9+
<catalog>
10+
<book id="...">
11+
<author>...</author>
12+
<title>...</title>
13+
</book>
14+
<book id="...">
15+
<author>...</author>
16+
<title>...</title>
17+
</book>
18+
...
19+
</catalog>.
20+
Each catalog represents the work of one distinct <author> in your library. There is exactly one <catalog> element in each xml_doc, and the id for each book is unique.
21+
22+
Given the catalogs table, you want to find out which authors you have represented in your library. Your task is to create a new table with the author column that will contain all the distinct authors, sorted by their names.
23+
24+
Example
25+
26+
For given table catalogs
27+
28+
doc_id xml_doc
29+
1
30+
<catalog>
31+
<book id="11">
32+
<author>Chuck Palahniuk</author>
33+
<title>Fight Club</title>
34+
</book>
35+
<book id="12">
36+
<author>Chuck Palahniuk</author>
37+
<title>Survivor</title>
38+
</book>
39+
</catalog>
40+
2
41+
<catalog>
42+
<book id="21">
43+
<author>Bernard Werber</author>
44+
<title>Les Thanatonautes</title>
45+
</book>
46+
</catalog>
47+
3
48+
<catalog>
49+
<book id="31">
50+
<author>Boris Vian</author>
51+
<title>The Big Sleep</title>
52+
</book>
53+
<book id="32">
54+
<author>Boris Vian</author>
55+
<title>The Lady in the Lake</title>
56+
</book>
57+
<book id="33">
58+
<author>Boris Vian</author>
59+
<title>The World of Null-A</title>
60+
</book>
61+
</catalog>
62+
the output should be
63+
64+
author
65+
Bernard Werber
66+
Boris Vian
67+
Chuck Palahniuk
68+
*/
69+
70+
CREATE PROCEDURE booksCatalogs()
71+
BEGIN
72+
select ExtractValue(xml_doc, '//book[1]/author') as author from catalogs order by author;
73+
END

0 commit comments

Comments
 (0)