我在MySQL中有两个表的设置:
我如何SELECT
没有会议的客户,或仅将开会时间设置为<> 0的会议
答案 0 :(得分:0)
应该执行NOT EXISTS
查询。
所有已召开<> 0的会议等于说未举行会议= 0:
SELECT *
FROM customers
WHERE NOT EXISTS (
SELECT *
FROM customar_meetings
WHERE customar_meetings.customar_id = customers.customar_id
AND meeting_held = 0
)
https://dbfiddle.uk/?rdbms=mysql_5.7&fiddle=d9e11e8d99dc9418c966b36d9012edb4
答案 1 :(得分:0)
详细但有效。
SELECT
*
FROM
customers
WHERE
NOT EXISTS( SELECT
*
FROM
customar_meetings
WHERE
customar_meetings.customar_id = customers.customar_id)
UNION SELECT
*
FROM
customers
WHERE
(SELECT
COUNT(*)
FROM
customar_meetings
WHERE
customar_meetings.customar_id = customers.customar_id) = 1
AND (SELECT
meeting_held
FROM
customar_meetings
WHERE
customar_meetings.customar_id = customers.customar_id
LIMIT 1) <> 0;