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 like '1%' or  
      (today.status like '3%' and tomorrow.work_ordertext is null) 
      GROUP BY today.code

我遇到了“tomorrow.work_ordertext is null”语句的问题。明天.code 和明天.work_ordertext 可能甚至不存在于表中,所以我猜它不应该是一个空语句。如果今天表中的状态类似于 3,明天表上不存在任何记录,我正在寻找一种从今天表中提取行的方法。对不起,如果这听起来令人困惑。

4

1 回答 1

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。

于 2012-07-19T14:08:20.217 回答