SELECT today.status, GROUP_CONCAT(tomorrow.work_order order by line), today.code, today.events
FROM today LEFT JOIN tomorrow
ON today.code = tomorrow.code
WHERE today.status like '1%' or
(today.status like '3%' and tomorrow.work_ordertext is null)
GROUP BY today.code
我遇到'tomorrow.work_ordertext is null'语句的问题。 tomorrow.code和tomorrow.work_ordertext甚至可能不存在于表中,所以我猜它不应该是一个空语句。我正在寻找一种方法来从今天的表中提取行,如果在今天的表中状态为3时明天表上没有记录。对不起,如果这听起来很混乱。
答案 0 :(得分:0)
SELECT today.status, GROUP_CONCAT(tomorrow.work_order order by line), today.code, today.events
FROM today LEFT JOIN tomorrow
ON today.code = tomorrow.code
WHERE today.status = 1 or
(today.status = 3 and isnull( tomorrow.work_ordertext ))
GROUP BY today.code
我取出了类似的状态,因为它将匹配1,10,1b,1somethingweird。