Answer the question
In order to leave comments, you need to log in
How can such SQL queries be formulated?
Good evening, yesterday I passed the exam on the database.
The teacher flunked me on three requests out of 9, I categorically do not understand what he wanted.
If it doesn't bother you, can you write how, in your opinion, it would be correct to present them?
This is how the tables look like:
FILM (F_NAME, DIRECTOR, YEAR),
CUSTOMER (CU_NAME, CU_CITY, CU_ADDRESS),
CINEMA(CI_NAME, CI_ADDRESS, CI_CHIEF),
LOAN(CU_NAME, F_NAME)
PROGRAM(F_NAME, CI_NAME, DATE
) :
1) Cinema names (CI_NAME) of cinemas from Pilsner (CI_ADDRESS like %Pilsner% ) and related amount of items on the PROGRAM (two tuples [F_NAME, DATE]). Include also CI_NAMEs of such cinemas, they have NO program yet into result set. Order the result ascending according to the amount of program items.
2) Cinema names (CI_NAME) and it's program (ie. F_NAME, DATE). The result set should also contain films without program.
3) Cinema addresses where at there is no "Forman" films in the program.
If translation is needed, please tell me.
Answer the question
In order to leave comments, you need to log in
SELECT `C`.`CI_NAME`, ISNULL(`P`.`CNT`, 0) AS `AMOUNT`
FROM `CINEMA` AS `C`
LEFT JOIN (
SELECT `CI_NAME`, COUNT(*) AS `CNT`
FROM `PROGRAM`
GROUP BY `CI_NAME`
) AS `P` ON `P`.`CI_NAME` = `C`.`CI_NAME`
WHERE (`CI_ADDRESS` LIKE '%Pilsner%')
ORDER BY `AMOUNT`
SELECT `P`.`CI_NAME`, `F`.`F_NAME`, `P`.`DATE`
FROM `FILMS` AS `F`
LEFT JOIN `PROGRAM` AS `P` ON `P`.`F_NAME` = `F`.`F_NAME`
ORDER BY `P`.`CI_NAME`, `P`.`DATE`
SELECT `C`.`CI_ADRESS`
FROM `CINEMA` AS `C`
LEFT JOIN (
SELECT DISTINCT `CI_NAME`
FROM `PROGRAM`
WHERE `F_NAME` = 'Forman'
) AS `P` ON `P`.`CI_NAME` = `C`.`CI_NAME`
WHERE `P`.`CI_NAME` IS NULL
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question