-
GROUP BY
できます ユーザーIDと名前について。 -
HAVING
を使用するSUM()
を含む句 ケースを除外するための集計。 - ユーザーが特定の日に仕事をしていない場合は、
SUM()
その日はゼロになり、参加を投稿します。
最初のケースの場合(正確に機能します) すべての曜日)、試してみてください:
SELECT u.id, u.name
FROM USERS AS u
JOIN WORKDAYS AS wd ON wd.user_id = u.id
JOIN DAYS AS d ON d.id = wd.day_id
GROUP BY u.id, u.name
HAVING SUM(d.name = 'monday')
AND SUM(d.name = 'tuesday')
AND SUM(d.name = 'wednesday')
AND SUM(d.name = 'thursday')
AND SUM(d.name = 'friday')
AND SUM(d.name = 'sunday') = 0
AND SUM(d.name = 'saturday') = 0
2番目のケースでは、sunday
の条件を削除するだけです。 およびsaturday
。試してみてください:
SELECT u.id, u.name
FROM USERS AS u
JOIN WORKDAYS AS wd ON wd.user_id = u.id
JOIN DAYS AS d ON d.id = wd.day_id
GROUP BY u.id, u.name
HAVING SUM(d.name = 'monday')
AND SUM(d.name = 'tuesday')
AND SUM(d.name = 'wednesday')
AND SUM(d.name = 'thursday')
AND SUM(d.name = 'friday')