<?xml version="1.0" encoding="UTF-8"?>
<quiz>
  <question type="category">
    <category><text>$course$/top/CodeLab Starter/SQL and Databases</text></category>
  </question>
  <question type="codelab">
    <name><text>01. All books after 1950</text></name>
    <questiontext format="html"><text><![CDATA[<p>Click <strong>Tables</strong> to inspect the schema. List the <code>title</code> of all books published after 1950.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>mysql</language>
    <template></template>
    <solution>SELECT title FROM book WHERE year &gt; 1950;
</solution>
    <prefix>CREATE TABLE author (id INT PRIMARY KEY, name VARCHAR(60) NOT NULL, country VARCHAR(40));
CREATE TABLE book (id INT PRIMARY KEY, title VARCHAR(80) NOT NULL, author_id INT, year INT, pages INT, FOREIGN KEY (author_id) REFERENCES author(id));
INSERT INTO author VALUES (1, 'Ivo Andric', 'Serbia'), (2, 'Mesa Selimovic', 'Bosnia'), (3, 'Milos Crnjanski', 'Serbia'), (4, 'Danilo Kis', 'Serbia');
INSERT INTO book VALUES (1, 'Na Drini cuprija', 1, 1945, 314), (2, 'Prokleta avlija', 1, 1954, 140), (3, 'Dervis i smrt', 2, 1966, 420), (4, 'Tvrdjava', 2, 1970, 380), (5, 'Seobe', 3, 1929, 260), (6, 'Enciklopedija mrtvih', 4, 1983, 190);</prefix>
    <suffix></suffix>
    <tests>[{"stdin":"","expected":"title\nProkleta avlija\nDervis i smrt\nTvrdjava\nEnciklopedija mrtvih\n","code":"","hidden":false,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>unordered</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>02. Books ordered by year descending</text></name>
    <questiontext format="html"><text><![CDATA[<p>List <code>title</code> and <code>year</code> of all books ordered from newest to oldest.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>mysql</language>
    <template></template>
    <solution>SELECT title, year FROM book ORDER BY year DESC;
</solution>
    <prefix>CREATE TABLE author (id INT PRIMARY KEY, name VARCHAR(60) NOT NULL, country VARCHAR(40));
CREATE TABLE book (id INT PRIMARY KEY, title VARCHAR(80) NOT NULL, author_id INT, year INT, pages INT, FOREIGN KEY (author_id) REFERENCES author(id));
INSERT INTO author VALUES (1, 'Ivo Andric', 'Serbia'), (2, 'Mesa Selimovic', 'Bosnia'), (3, 'Milos Crnjanski', 'Serbia'), (4, 'Danilo Kis', 'Serbia');
INSERT INTO book VALUES (1, 'Na Drini cuprija', 1, 1945, 314), (2, 'Prokleta avlija', 1, 1954, 140), (3, 'Dervis i smrt', 2, 1966, 420), (4, 'Tvrdjava', 2, 1970, 380), (5, 'Seobe', 3, 1929, 260), (6, 'Enciklopedija mrtvih', 4, 1983, 190);</prefix>
    <suffix></suffix>
    <tests>[{"stdin":"","expected":"title\tyear\nEnciklopedija mrtvih\t1983\nTvrdjava\t1970\nDervis i smrt\t1966\nProkleta avlija\t1954\nNa Drini cuprija\t1945\nSeobe\t1929\n","code":"","hidden":false,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>03. Longest book (LIMIT)</text></name>
    <questiontext format="html"><text><![CDATA[<p>Print the <code>title</code> and <code>pages</code> of the single book with the most pages.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>mysql</language>
    <template></template>
    <solution>SELECT title, pages FROM book ORDER BY pages DESC LIMIT 1;
</solution>
    <prefix>CREATE TABLE author (id INT PRIMARY KEY, name VARCHAR(60) NOT NULL, country VARCHAR(40));
CREATE TABLE book (id INT PRIMARY KEY, title VARCHAR(80) NOT NULL, author_id INT, year INT, pages INT, FOREIGN KEY (author_id) REFERENCES author(id));
INSERT INTO author VALUES (1, 'Ivo Andric', 'Serbia'), (2, 'Mesa Selimovic', 'Bosnia'), (3, 'Milos Crnjanski', 'Serbia'), (4, 'Danilo Kis', 'Serbia');
INSERT INTO book VALUES (1, 'Na Drini cuprija', 1, 1945, 314), (2, 'Prokleta avlija', 1, 1954, 140), (3, 'Dervis i smrt', 2, 1966, 420), (4, 'Tvrdjava', 2, 1970, 380), (5, 'Seobe', 3, 1929, 260), (6, 'Enciklopedija mrtvih', 4, 1983, 190);</prefix>
    <suffix></suffix>
    <tests>[{"stdin":"","expected":"title\tpages\nDervis i smrt\t420\n","code":"","hidden":false,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>04. Join books with author names</text></name>
    <questiontext format="html"><text><![CDATA[<p>List each book <code>title</code> together with its author's <code>name</code> (only books with more than 250 pages).</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>mysql</language>
    <template></template>
    <solution>SELECT b.title, a.name FROM book b JOIN author a ON b.author_id = a.id WHERE b.pages &gt; 250;
</solution>
    <prefix>CREATE TABLE author (id INT PRIMARY KEY, name VARCHAR(60) NOT NULL, country VARCHAR(40));
CREATE TABLE book (id INT PRIMARY KEY, title VARCHAR(80) NOT NULL, author_id INT, year INT, pages INT, FOREIGN KEY (author_id) REFERENCES author(id));
INSERT INTO author VALUES (1, 'Ivo Andric', 'Serbia'), (2, 'Mesa Selimovic', 'Bosnia'), (3, 'Milos Crnjanski', 'Serbia'), (4, 'Danilo Kis', 'Serbia');
INSERT INTO book VALUES (1, 'Na Drini cuprija', 1, 1945, 314), (2, 'Prokleta avlija', 1, 1954, 140), (3, 'Dervis i smrt', 2, 1966, 420), (4, 'Tvrdjava', 2, 1970, 380), (5, 'Seobe', 3, 1929, 260), (6, 'Enciklopedija mrtvih', 4, 1983, 190);</prefix>
    <suffix></suffix>
    <tests>[{"stdin":"","expected":"title\tname\nNa Drini cuprija\tIvo Andric\nDervis i smrt\tMesa Selimovic\nTvrdjava\tMesa Selimovic\nSeobe\tMilos Crnjanski\n","code":"","hidden":false,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>unordered</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>05. Books per author (GROUP BY)</text></name>
    <questiontext format="html"><text><![CDATA[<p>List each author <code>name</code> and the number of their books (aliased as <code>cnt</code>), ordered by <code>name</code>.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>mysql</language>
    <template></template>
    <solution>SELECT a.name, COUNT(b.id) AS cnt FROM author a JOIN book b ON b.author_id = a.id GROUP BY a.id, a.name ORDER BY a.name;
</solution>
    <prefix>CREATE TABLE author (id INT PRIMARY KEY, name VARCHAR(60) NOT NULL, country VARCHAR(40));
CREATE TABLE book (id INT PRIMARY KEY, title VARCHAR(80) NOT NULL, author_id INT, year INT, pages INT, FOREIGN KEY (author_id) REFERENCES author(id));
INSERT INTO author VALUES (1, 'Ivo Andric', 'Serbia'), (2, 'Mesa Selimovic', 'Bosnia'), (3, 'Milos Crnjanski', 'Serbia'), (4, 'Danilo Kis', 'Serbia');
INSERT INTO book VALUES (1, 'Na Drini cuprija', 1, 1945, 314), (2, 'Prokleta avlija', 1, 1954, 140), (3, 'Dervis i smrt', 2, 1966, 420), (4, 'Tvrdjava', 2, 1970, 380), (5, 'Seobe', 3, 1929, 260), (6, 'Enciklopedija mrtvih', 4, 1983, 190);</prefix>
    <suffix></suffix>
    <tests>[{"stdin":"","expected":"name\tcnt\nDanilo Kis\t1\nIvo Andric\t2\nMesa Selimovic\t2\nMilos Crnjanski\t1\n","code":"","hidden":false,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>06. Authors with at least 2 books (HAVING)</text></name>
    <questiontext format="html"><text><![CDATA[<p>List the <code>name</code> of authors who have at least 2 books in the database.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>mysql</language>
    <template></template>
    <solution>SELECT a.name FROM author a JOIN book b ON b.author_id = a.id GROUP BY a.id, a.name HAVING COUNT(b.id) &gt;= 2;
</solution>
    <prefix>CREATE TABLE author (id INT PRIMARY KEY, name VARCHAR(60) NOT NULL, country VARCHAR(40));
CREATE TABLE book (id INT PRIMARY KEY, title VARCHAR(80) NOT NULL, author_id INT, year INT, pages INT, FOREIGN KEY (author_id) REFERENCES author(id));
INSERT INTO author VALUES (1, 'Ivo Andric', 'Serbia'), (2, 'Mesa Selimovic', 'Bosnia'), (3, 'Milos Crnjanski', 'Serbia'), (4, 'Danilo Kis', 'Serbia');
INSERT INTO book VALUES (1, 'Na Drini cuprija', 1, 1945, 314), (2, 'Prokleta avlija', 1, 1954, 140), (3, 'Dervis i smrt', 2, 1966, 420), (4, 'Tvrdjava', 2, 1970, 380), (5, 'Seobe', 3, 1929, 260), (6, 'Enciklopedija mrtvih', 4, 1983, 190);</prefix>
    <suffix></suffix>
    <tests>[{"stdin":"","expected":"name\nIvo Andric\nMesa Selimovic\n","code":"","hidden":false,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>unordered</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>07. Total pages by country</text></name>
    <questiontext format="html"><text><![CDATA[<p>Print each <code>country</code> and total <code>pages</code> (aliased as <code>total_pages</code>) across its authors' books, ordered by <code>country</code>.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>mysql</language>
    <template></template>
    <solution>SELECT a.country, SUM(b.pages) AS total_pages FROM author a JOIN book b ON b.author_id = a.id GROUP BY a.country ORDER BY a.country;
</solution>
    <prefix>CREATE TABLE author (id INT PRIMARY KEY, name VARCHAR(60) NOT NULL, country VARCHAR(40));
CREATE TABLE book (id INT PRIMARY KEY, title VARCHAR(80) NOT NULL, author_id INT, year INT, pages INT, FOREIGN KEY (author_id) REFERENCES author(id));
INSERT INTO author VALUES (1, 'Ivo Andric', 'Serbia'), (2, 'Mesa Selimovic', 'Bosnia'), (3, 'Milos Crnjanski', 'Serbia'), (4, 'Danilo Kis', 'Serbia');
INSERT INTO book VALUES (1, 'Na Drini cuprija', 1, 1945, 314), (2, 'Prokleta avlija', 1, 1954, 140), (3, 'Dervis i smrt', 2, 1966, 420), (4, 'Tvrdjava', 2, 1970, 380), (5, 'Seobe', 3, 1929, 260), (6, 'Enciklopedija mrtvih', 4, 1983, 190);</prefix>
    <suffix></suffix>
    <tests>[{"stdin":"","expected":"country\ttotal_pages\nBosnia\t800\nSerbia\t904\n","code":"","hidden":false,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>08. Books thicker than average (subquery)</text></name>
    <questiontext format="html"><text><![CDATA[<p>List the <code>title</code> of books whose page count is strictly greater than the average page count of all books.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>mysql</language>
    <template></template>
    <solution>SELECT title FROM book WHERE pages &gt; (SELECT AVG(pages) FROM book);
</solution>
    <prefix>CREATE TABLE author (id INT PRIMARY KEY, name VARCHAR(60) NOT NULL, country VARCHAR(40));
CREATE TABLE book (id INT PRIMARY KEY, title VARCHAR(80) NOT NULL, author_id INT, year INT, pages INT, FOREIGN KEY (author_id) REFERENCES author(id));
INSERT INTO author VALUES (1, 'Ivo Andric', 'Serbia'), (2, 'Mesa Selimovic', 'Bosnia'), (3, 'Milos Crnjanski', 'Serbia'), (4, 'Danilo Kis', 'Serbia');
INSERT INTO book VALUES (1, 'Na Drini cuprija', 1, 1945, 314), (2, 'Prokleta avlija', 1, 1954, 140), (3, 'Dervis i smrt', 2, 1966, 420), (4, 'Tvrdjava', 2, 1970, 380), (5, 'Seobe', 3, 1929, 260), (6, 'Enciklopedija mrtvih', 4, 1983, 190);</prefix>
    <suffix></suffix>
    <tests>[{"stdin":"","expected":"title\nNa Drini cuprija\nDervis i smrt\nTvrdjava\n","code":"","hidden":false,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>unordered</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
</quiz>
