Answer the question
In order to leave comments, you need to log in
How to write similar sql query?
Good afternoon. There is a similar task, so far there are only assumptions on it.
I myself learn sql by sql-ex solving problems (stopped at 15). I've been scratching my head over it for about a week now. Thanks in advance for any hints.
from attempts there is a similar one, but I'm not sure if this is what you need
SELECT id_object
FROM ( — объекты где умер последний собственник более указанного количества месяцев
SELECT id_object, max(dead) as lastdead
FROM —список собствеников
—- INNER JOIN др. таблицы для опр. даты смерти (dead)
INNER JOIN some tables for death date
GROUP BY id_object
HAVING max(dead) < нужная дата
) AS deadobjects
WHERE ( — на момент смерти последнего собственника не было ни одного живого зарегистрированного
NOT EXISTS ( — список живых зарегистрированных по указанному объекту на заданную дату
SELECT * FROM residence
WHERE id_residence_type =1 and begin_date<lastdead and end_date>lastdead —живые на указанную дату
AND deadobjects.id_object =id_residence.type.id_object —по указанному объекту
)
)
AND
NOT EXISTS ( —живые собственники
)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question