/jOOQ-examples/Sakila/sqlite-sakila-db/sqlite-sakila-schema.sql

http://github.com/jOOQ/jOOQ · SQL · 645 lines · 452 code · 84 blank · 109 comment · 1 complexity · 17176eb760c79218e505b42a501d0a85 MD5 · raw file

  1. /*
  2. Sakila for SQLite is a port of the Sakila example database available for MySQL, which was originally developed by Mike Hillyer of the MySQL AB documentation team.
  3. This project is designed to help database administrators to decide which database to use for development of new products
  4. The user can run the same SQL against different kind of databases and compare the performance
  5. License: BSD
  6. Copyright DB Software Laboratory
  7. http://www.etl-tools.com
  8. */
  9. --
  10. -- Table structure for table actor
  11. --
  12. --DROP TABLE actor;
  13. CREATE TABLE actor (
  14. actor_id numeric NOT NULL ,
  15. first_name VARCHAR(45) NOT NULL,
  16. last_name VARCHAR(45) NOT NULL,
  17. last_update TIMESTAMP NOT NULL,
  18. PRIMARY KEY (actor_id)
  19. )
  20. ;
  21. CREATE INDEX idx_actor_last_name ON actor(last_name)
  22. ;
  23. CREATE TRIGGER actor_trigger_ai AFTER INSERT ON actor
  24. BEGIN
  25. UPDATE actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  26. END
  27. ;
  28. CREATE TRIGGER actor_trigger_au AFTER UPDATE ON actor
  29. BEGIN
  30. UPDATE actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  31. END
  32. ;
  33. --
  34. -- Table structure for table country
  35. --
  36. CREATE TABLE country (
  37. country_id SMALLINT NOT NULL,
  38. country VARCHAR(50) NOT NULL,
  39. last_update TIMESTAMP,
  40. PRIMARY KEY (country_id)
  41. )
  42. ;
  43. CREATE TRIGGER country_trigger_ai AFTER INSERT ON country
  44. BEGIN
  45. UPDATE country SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  46. END
  47. ;
  48. CREATE TRIGGER country_trigger_au AFTER UPDATE ON country
  49. BEGIN
  50. UPDATE country SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  51. END
  52. ;
  53. --
  54. -- Table structure for table city
  55. --
  56. CREATE TABLE city (
  57. city_id int NOT NULL,
  58. city VARCHAR(50) NOT NULL,
  59. country_id SMALLINT NOT NULL,
  60. last_update TIMESTAMP NOT NULL,
  61. PRIMARY KEY (city_id),
  62. CONSTRAINT fk_city_country FOREIGN KEY (country_id) REFERENCES country (country_id) ON DELETE NO ACTION ON UPDATE CASCADE
  63. )
  64. ;
  65. CREATE INDEX idx_fk_country_id ON city(country_id)
  66. ;
  67. CREATE TRIGGER city_trigger_ai AFTER INSERT ON city
  68. BEGIN
  69. UPDATE city SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  70. END
  71. ;
  72. CREATE TRIGGER city_trigger_au AFTER UPDATE ON city
  73. BEGIN
  74. UPDATE city SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  75. END
  76. ;
  77. --
  78. -- Table structure for table address
  79. --
  80. CREATE TABLE address (
  81. address_id int NOT NULL,
  82. address VARCHAR(50) NOT NULL,
  83. address2 VARCHAR(50) DEFAULT NULL,
  84. district VARCHAR(20) NOT NULL,
  85. city_id INT NOT NULL,
  86. postal_code VARCHAR(10) DEFAULT NULL,
  87. phone VARCHAR(20) NOT NULL,
  88. last_update TIMESTAMP NOT NULL,
  89. PRIMARY KEY (address_id),
  90. CONSTRAINT fk_address_city FOREIGN KEY (city_id) REFERENCES city (city_id) ON DELETE NO ACTION ON UPDATE CASCADE
  91. )
  92. ;
  93. CREATE INDEX idx_fk_city_id ON address(city_id)
  94. ;
  95. CREATE TRIGGER address_trigger_ai AFTER INSERT ON address
  96. BEGIN
  97. UPDATE address SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  98. END
  99. ;
  100. CREATE TRIGGER address_trigger_au AFTER UPDATE ON address
  101. BEGIN
  102. UPDATE address SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  103. END
  104. ;
  105. --
  106. -- Table structure for table language
  107. --
  108. CREATE TABLE language (
  109. language_id SMALLINT NOT NULL ,
  110. name CHAR(20) NOT NULL,
  111. last_update TIMESTAMP NOT NULL,
  112. PRIMARY KEY (language_id)
  113. )
  114. ;
  115. CREATE TRIGGER language_trigger_ai AFTER INSERT ON language
  116. BEGIN
  117. UPDATE language SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  118. END
  119. ;
  120. CREATE TRIGGER language_trigger_au AFTER UPDATE ON language
  121. BEGIN
  122. UPDATE language SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  123. END
  124. ;
  125. --
  126. -- Table structure for table category
  127. --
  128. CREATE TABLE category (
  129. category_id SMALLINT NOT NULL,
  130. name VARCHAR(25) NOT NULL,
  131. last_update TIMESTAMP NOT NULL,
  132. PRIMARY KEY (category_id)
  133. );
  134. CREATE TRIGGER category_trigger_ai AFTER INSERT ON category
  135. BEGIN
  136. UPDATE category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  137. END
  138. ;
  139. CREATE TRIGGER category_trigger_au AFTER UPDATE ON category
  140. BEGIN
  141. UPDATE category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  142. END
  143. ;
  144. --
  145. -- Table structure for table customer
  146. --
  147. CREATE TABLE customer (
  148. customer_id INT NOT NULL,
  149. store_id INT NOT NULL,
  150. first_name VARCHAR(45) NOT NULL,
  151. last_name VARCHAR(45) NOT NULL,
  152. email VARCHAR(50) DEFAULT NULL,
  153. address_id INT NOT NULL,
  154. active CHAR(1) DEFAULT 'Y' NOT NULL,
  155. create_date TIMESTAMP NOT NULL,
  156. last_update TIMESTAMP NOT NULL,
  157. PRIMARY KEY (customer_id),
  158. CONSTRAINT fk_customer_store FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE NO ACTION ON UPDATE CASCADE,
  159. CONSTRAINT fk_customer_address FOREIGN KEY (address_id) REFERENCES address (address_id) ON DELETE NO ACTION ON UPDATE CASCADE
  160. )
  161. ;
  162. CREATE INDEX idx_customer_fk_store_id ON customer(store_id)
  163. ;
  164. CREATE INDEX idx_customer_fk_address_id ON customer(address_id)
  165. ;
  166. CREATE INDEX idx_customer_last_name ON customer(last_name)
  167. ;
  168. CREATE TRIGGER customer_trigger_ai AFTER INSERT ON customer
  169. BEGIN
  170. UPDATE customer SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  171. END
  172. ;
  173. CREATE TRIGGER customer_trigger_au AFTER UPDATE ON customer
  174. BEGIN
  175. UPDATE customer SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  176. END
  177. ;
  178. --
  179. -- Table structure for table film
  180. --
  181. CREATE TABLE film (
  182. film_id int NOT NULL,
  183. title VARCHAR(255) NOT NULL,
  184. description BLOB SUB_TYPE TEXT DEFAULT NULL,
  185. release_year VARCHAR(4) DEFAULT NULL,
  186. language_id SMALLINT NOT NULL,
  187. original_language_id SMALLINT DEFAULT NULL,
  188. rental_duration SMALLINT DEFAULT 3 NOT NULL,
  189. rental_rate DECIMAL(4,2) DEFAULT 4.99 NOT NULL,
  190. length SMALLINT DEFAULT NULL,
  191. replacement_cost DECIMAL(5,2) DEFAULT 19.99 NOT NULL,
  192. rating VARCHAR(10) DEFAULT 'G',
  193. special_features VARCHAR(100) DEFAULT NULL,
  194. last_update TIMESTAMP NOT NULL,
  195. PRIMARY KEY (film_id),
  196. CONSTRAINT CHECK_special_features CHECK(special_features is null or
  197. special_features like '%Trailers%' or
  198. special_features like '%Commentaries%' or
  199. special_features like '%Deleted Scenes%' or
  200. special_features like '%Behind the Scenes%'),
  201. CONSTRAINT CHECK_special_rating CHECK(rating in ('G','PG','PG-13','R','NC-17')),
  202. CONSTRAINT fk_film_language FOREIGN KEY (language_id) REFERENCES language (language_id) ,
  203. CONSTRAINT fk_film_language_original FOREIGN KEY (original_language_id) REFERENCES language (language_id)
  204. )
  205. ;
  206. CREATE INDEX idx_fk_language_id ON film(language_id)
  207. ;
  208. CREATE INDEX idx_fk_original_language_id ON film(original_language_id)
  209. ;
  210. CREATE TRIGGER film_trigger_ai AFTER INSERT ON film
  211. BEGIN
  212. UPDATE film SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  213. END
  214. ;
  215. CREATE TRIGGER film_trigger_au AFTER UPDATE ON film
  216. BEGIN
  217. UPDATE film SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  218. END
  219. ;
  220. --
  221. -- Table structure for table film_actor
  222. --
  223. CREATE TABLE film_actor (
  224. actor_id INT NOT NULL,
  225. film_id INT NOT NULL,
  226. last_update TIMESTAMP NOT NULL,
  227. PRIMARY KEY (actor_id,film_id),
  228. CONSTRAINT fk_film_actor_actor FOREIGN KEY (actor_id) REFERENCES actor (actor_id) ON DELETE NO ACTION ON UPDATE CASCADE,
  229. CONSTRAINT fk_film_actor_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE NO ACTION ON UPDATE CASCADE
  230. )
  231. ;
  232. CREATE INDEX idx_fk_film_actor_film ON film_actor(film_id)
  233. ;
  234. CREATE INDEX idx_fk_film_actor_actor ON film_actor(actor_id)
  235. ;
  236. CREATE TRIGGER film_actor_trigger_ai AFTER INSERT ON film_actor
  237. BEGIN
  238. UPDATE film_actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  239. END
  240. ;
  241. CREATE TRIGGER film_actor_trigger_au AFTER UPDATE ON film_actor
  242. BEGIN
  243. UPDATE film_actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  244. END
  245. ;
  246. --
  247. -- Table structure for table film_category
  248. --
  249. CREATE TABLE film_category (
  250. film_id INT NOT NULL,
  251. category_id SMALLINT NOT NULL,
  252. last_update TIMESTAMP NOT NULL,
  253. PRIMARY KEY (film_id, category_id),
  254. CONSTRAINT fk_film_category_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE NO ACTION ON UPDATE CASCADE,
  255. CONSTRAINT fk_film_category_category FOREIGN KEY (category_id) REFERENCES category (category_id) ON DELETE NO ACTION ON UPDATE CASCADE
  256. )
  257. ;
  258. CREATE INDEX idx_fk_film_category_film ON film_category(film_id)
  259. ;
  260. CREATE INDEX idx_fk_film_category_category ON film_category(category_id)
  261. ;
  262. CREATE TRIGGER film_category_trigger_ai AFTER INSERT ON film_category
  263. BEGIN
  264. UPDATE film_category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  265. END
  266. ;
  267. CREATE TRIGGER film_category_trigger_au AFTER UPDATE ON film_category
  268. BEGIN
  269. UPDATE film_category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  270. END
  271. ;
  272. --
  273. -- Table structure for table film_text
  274. --
  275. CREATE TABLE film_text (
  276. film_id SMALLINT NOT NULL,
  277. title VARCHAR(255) NOT NULL,
  278. description BLOB SUB_TYPE TEXT,
  279. PRIMARY KEY (film_id)
  280. )
  281. ;
  282. --
  283. -- Table structure for table inventory
  284. --
  285. CREATE TABLE inventory (
  286. inventory_id INT NOT NULL,
  287. film_id INT NOT NULL,
  288. store_id INT NOT NULL,
  289. last_update TIMESTAMP NOT NULL,
  290. PRIMARY KEY (inventory_id),
  291. CONSTRAINT fk_inventory_store FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE NO ACTION ON UPDATE CASCADE,
  292. CONSTRAINT fk_inventory_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE NO ACTION ON UPDATE CASCADE
  293. )
  294. ;
  295. CREATE INDEX idx_fk_film_id ON inventory(film_id)
  296. ;
  297. CREATE INDEX idx_fk_film_id_store_id ON inventory(store_id,film_id)
  298. ;
  299. CREATE TRIGGER inventory_trigger_ai AFTER INSERT ON inventory
  300. BEGIN
  301. UPDATE inventory SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  302. END
  303. ;
  304. CREATE TRIGGER inventory_trigger_au AFTER UPDATE ON inventory
  305. BEGIN
  306. UPDATE inventory SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  307. END
  308. ;
  309. --
  310. -- Table structure for table staff
  311. --
  312. CREATE TABLE staff (
  313. staff_id SMALLINT NOT NULL,
  314. first_name VARCHAR(45) NOT NULL,
  315. last_name VARCHAR(45) NOT NULL,
  316. address_id INT NOT NULL,
  317. picture BLOB DEFAULT NULL,
  318. email VARCHAR(50) DEFAULT NULL,
  319. store_id INT NOT NULL,
  320. active SMALLINT DEFAULT 1 NOT NULL,
  321. username VARCHAR(16) NOT NULL,
  322. password VARCHAR(40) DEFAULT NULL,
  323. last_update TIMESTAMP NOT NULL,
  324. PRIMARY KEY (staff_id),
  325. CONSTRAINT fk_staff_store FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE NO ACTION ON UPDATE CASCADE,
  326. CONSTRAINT fk_staff_address FOREIGN KEY (address_id) REFERENCES address (address_id) ON DELETE NO ACTION ON UPDATE CASCADE
  327. )
  328. ;
  329. CREATE INDEX idx_fk_staff_store_id ON staff(store_id)
  330. ;
  331. CREATE INDEX idx_fk_staff_address_id ON staff(address_id)
  332. ;
  333. CREATE TRIGGER staff_trigger_ai AFTER INSERT ON staff
  334. BEGIN
  335. UPDATE staff SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  336. END
  337. ;
  338. CREATE TRIGGER staff_trigger_au AFTER UPDATE ON staff
  339. BEGIN
  340. UPDATE staff SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  341. END
  342. ;
  343. --
  344. -- Table structure for table store
  345. --
  346. CREATE TABLE store (
  347. store_id INT NOT NULL,
  348. manager_staff_id SMALLINT NOT NULL,
  349. address_id INT NOT NULL,
  350. last_update TIMESTAMP NOT NULL,
  351. PRIMARY KEY (store_id),
  352. CONSTRAINT fk_store_staff FOREIGN KEY (manager_staff_id) REFERENCES staff (staff_id) ,
  353. CONSTRAINT fk_store_address FOREIGN KEY (address_id) REFERENCES address (address_id)
  354. )
  355. ;
  356. CREATE INDEX idx_store_fk_manager_staff_id ON store(manager_staff_id)
  357. ;
  358. CREATE INDEX idx_fk_store_address ON store(address_id)
  359. ;
  360. CREATE TRIGGER store_trigger_ai AFTER INSERT ON store
  361. BEGIN
  362. UPDATE store SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  363. END
  364. ;
  365. CREATE TRIGGER store_trigger_au AFTER UPDATE ON store
  366. BEGIN
  367. UPDATE store SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  368. END
  369. ;
  370. --
  371. -- Table structure for table payment
  372. --
  373. CREATE TABLE payment (
  374. payment_id int NOT NULL,
  375. customer_id INT NOT NULL,
  376. staff_id SMALLINT NOT NULL,
  377. rental_id INT DEFAULT NULL,
  378. amount DECIMAL(5,2) NOT NULL,
  379. payment_date TIMESTAMP NOT NULL,
  380. last_update TIMESTAMP NOT NULL,
  381. PRIMARY KEY (payment_id),
  382. CONSTRAINT fk_payment_rental FOREIGN KEY (rental_id) REFERENCES rental (rental_id) ON DELETE SET NULL ON UPDATE CASCADE,
  383. CONSTRAINT fk_payment_customer FOREIGN KEY (customer_id) REFERENCES customer (customer_id) ,
  384. CONSTRAINT fk_payment_staff FOREIGN KEY (staff_id) REFERENCES staff (staff_id)
  385. )
  386. ;
  387. CREATE INDEX idx_fk_staff_id ON payment(staff_id)
  388. ;
  389. CREATE INDEX idx_fk_customer_id ON payment(customer_id)
  390. ;
  391. CREATE TRIGGER payment_trigger_ai AFTER INSERT ON payment
  392. BEGIN
  393. UPDATE payment SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  394. END
  395. ;
  396. CREATE TRIGGER payment_trigger_au AFTER UPDATE ON payment
  397. BEGIN
  398. UPDATE payment SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  399. END
  400. ;
  401. CREATE TABLE rental (
  402. rental_id INT NOT NULL,
  403. rental_date TIMESTAMP NOT NULL,
  404. inventory_id INT NOT NULL,
  405. customer_id INT NOT NULL,
  406. return_date TIMESTAMP DEFAULT NULL,
  407. staff_id SMALLINT NOT NULL,
  408. last_update TIMESTAMP NOT NULL,
  409. PRIMARY KEY (rental_id),
  410. CONSTRAINT fk_rental_staff FOREIGN KEY (staff_id) REFERENCES staff (staff_id) ,
  411. CONSTRAINT fk_rental_inventory FOREIGN KEY (inventory_id) REFERENCES inventory (inventory_id) ,
  412. CONSTRAINT fk_rental_customer FOREIGN KEY (customer_id) REFERENCES customer (customer_id)
  413. )
  414. ;
  415. CREATE INDEX idx_rental_fk_inventory_id ON rental(inventory_id)
  416. ;
  417. CREATE INDEX idx_rental_fk_customer_id ON rental(customer_id)
  418. ;
  419. CREATE INDEX idx_rental_fk_staff_id ON rental(staff_id)
  420. ;
  421. CREATE UNIQUE INDEX idx_rental_uq ON rental (rental_date,inventory_id,customer_id)
  422. ;
  423. CREATE TRIGGER rental_trigger_ai AFTER INSERT ON rental
  424. BEGIN
  425. UPDATE rental SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  426. END
  427. ;
  428. CREATE TRIGGER rental_trigger_au AFTER UPDATE ON rental
  429. BEGIN
  430. UPDATE rental SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
  431. END
  432. ;
  433. --
  434. -- View structure for view customer_list
  435. --
  436. CREATE VIEW customer_list
  437. AS
  438. SELECT cu.customer_id AS ID,
  439. cu.first_name||' '||cu.last_name AS name,
  440. a.address AS address,
  441. a.postal_code AS zip_code,
  442. a.phone AS phone,
  443. city.city AS city,
  444. country.country AS country,
  445. case when cu.active=1 then 'active' else '' end AS notes,
  446. cu.store_id AS SID
  447. FROM customer AS cu JOIN address AS a ON cu.address_id = a.address_id JOIN city ON a.city_id = city.city_id
  448. JOIN country ON city.country_id = country.country_id
  449. ;
  450. --
  451. -- View structure for view film_list
  452. --
  453. CREATE VIEW film_list
  454. AS
  455. SELECT film.film_id AS FID,
  456. film.title AS title,
  457. film.description AS description,
  458. category.name AS category,
  459. film.rental_rate AS price,
  460. film.length AS length,
  461. film.rating AS rating,
  462. actor.first_name||' '||actor.last_name AS actors
  463. FROM category LEFT JOIN film_category ON category.category_id = film_category.category_id LEFT JOIN film ON film_category.film_id = film.film_id
  464. JOIN film_actor ON film.film_id = film_actor.film_id
  465. JOIN actor ON film_actor.actor_id = actor.actor_id
  466. ;
  467. --
  468. -- View structure for view staff_list
  469. --
  470. CREATE VIEW staff_list
  471. AS
  472. SELECT s.staff_id AS ID,
  473. s.first_name||' '||s.last_name AS name,
  474. a.address AS address,
  475. a.postal_code AS zip_code,
  476. a.phone AS phone,
  477. city.city AS city,
  478. country.country AS country,
  479. s.store_id AS SID
  480. FROM staff AS s JOIN address AS a ON s.address_id = a.address_id JOIN city ON a.city_id = city.city_id
  481. JOIN country ON city.country_id = country.country_id
  482. ;
  483. --
  484. -- View structure for view sales_by_store
  485. --
  486. CREATE VIEW sales_by_store
  487. AS
  488. SELECT
  489. s.store_id
  490. ,c.city||','||cy.country AS store
  491. ,m.first_name||' '||m.last_name AS manager
  492. ,SUM(p.amount) AS total_sales
  493. FROM payment AS p
  494. INNER JOIN rental AS r ON p.rental_id = r.rental_id
  495. INNER JOIN inventory AS i ON r.inventory_id = i.inventory_id
  496. INNER JOIN store AS s ON i.store_id = s.store_id
  497. INNER JOIN address AS a ON s.address_id = a.address_id
  498. INNER JOIN city AS c ON a.city_id = c.city_id
  499. INNER JOIN country AS cy ON c.country_id = cy.country_id
  500. INNER JOIN staff AS m ON s.manager_staff_id = m.staff_id
  501. GROUP BY
  502. s.store_id
  503. , c.city||','||cy.country
  504. , m.first_name||' '||m.last_name
  505. ;
  506. --
  507. -- View structure for view sales_by_film_category
  508. --
  509. -- Note that total sales will add up to >100% because
  510. -- some titles belong to more than 1 category
  511. --
  512. CREATE VIEW sales_by_film_category
  513. AS
  514. SELECT
  515. c.name AS category
  516. , SUM(p.amount) AS total_sales
  517. FROM payment AS p
  518. INNER JOIN rental AS r ON p.rental_id = r.rental_id
  519. INNER JOIN inventory AS i ON r.inventory_id = i.inventory_id
  520. INNER JOIN film AS f ON i.film_id = f.film_id
  521. INNER JOIN film_category AS fc ON f.film_id = fc.film_id
  522. INNER JOIN category AS c ON fc.category_id = c.category_id
  523. GROUP BY c.name
  524. ;
  525. --
  526. -- View structure for view actor_info
  527. --
  528. /*
  529. CREATE VIEW actor_info
  530. AS
  531. SELECT
  532. a.actor_id,
  533. a.first_name,
  534. a.last_name,
  535. GROUP_CONCAT(DISTINCT CONCAT(c.name, ': ',
  536. (SELECT GROUP_CONCAT(f.title ORDER BY f.title SEPARATOR ', ')
  537. FROM sakila.film f
  538. INNER JOIN sakila.film_category fc
  539. ON f.film_id = fc.film_id
  540. INNER JOIN sakila.film_actor fa
  541. ON f.film_id = fa.film_id
  542. WHERE fc.category_id = c.category_id
  543. AND fa.actor_id = a.actor_id
  544. )
  545. )
  546. ORDER BY c.name SEPARATOR '; ')
  547. AS film_info
  548. FROM sakila.actor a
  549. LEFT JOIN sakila.film_actor fa
  550. ON a.actor_id = fa.actor_id
  551. LEFT JOIN sakila.film_category fc
  552. ON fa.film_id = fc.film_id
  553. LEFT JOIN sakila.category c
  554. ON fc.category_id = c.category_id
  555. GROUP BY a.actor_id, a.first_name, a.last_name;
  556. */
  557. -- TO DO PROCEDURES
  558. -- TO DO TRIGGERS