Answer the question
In order to leave comments, you need to log in
How to complete the SQL query to exclude options?
SELECT
a.*
FROM(
SELECT
dbo.recipient.id,
dbo.recipient.name,
dbo.recipient.email,
dbo.recipient.phone/*,
dbo.reservation.humanid
dbo.reservation.number,
dbo.reservation.cdate*/
FROM
(SELECT
(SELECT top 1 dbo.human.id
FROM dbo.human
INNER JOIN dbo.people ON dbo.people.humanid = dbo.human.id
INNER JOIN dbo.recipient ON dbo.recipient.id = dbo.human.id
WHERE dbo.people.reservationid = p.id AND (dbo.recipient.phone != '' OR dbo.recipient.email != '')
ORDER BY dbo.human.born) AS huid,
p.id,
p.number
FROM dbo.reservation AS p
WHERE (SELECT top 1 dbo.human.id FROM dbo.human
INNER JOIN dbo.people ON dbo.people.humanid = dbo.human.id
INNER JOIN dbo.recipient ON dbo.recipient.id = dbo.human.id
WHERE dbo.human.born IS NOT NULL AND dbo.people.reservationid = p.id
) IS NOT NULL AND p.statusid = 1
)
AS huborn
INNER JOIN dbo.recipient ON dbo.recipient.id = huborn.huid
INNER JOIN dbo.human ON huborn.huid = dbo.human.id
INNER JOIN dbo.reservation ON dbo.reservation.id = huborn.id
INNER JOIN (SELECT MIN(dbo.subclaim.datebeg)AS dbeg,
dbo.subclaim.reservationid FROM dbo.subclaim
GROUP BY dbo.subclaim.reservationid
)AS sub ON sub.reservationid = dbo.reservation.id
WHERE
(dbo.human.human = 'ADL') AND (dbo.human.born IS NOT NULL)
AND DateDiff(day, sub.dbeg, '2015-07-07') < 548
) AS a GROUP by a.id, a.name, a.phone, a.email
) AS a WHERE a.id NOT IN() GROUP by a.id, a.name, a.phone, a.email
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