这是我的查询…我试图找到所有包含多个容器的BLNUMBERS,其中所有容器的“status=”。为什么这不起作用?我现在得到一些BLNUMBERS,其中所有容器的状态都是'status='',但也有一些容器的状态是''。编辑:如何查找某些容器“status=”和某些容器“status”的BLNUMBERS SELECT DISTINCT BLNUMBER #,CONTAINERNUMBER ,COUNT(CONTAINERNUMBER) AS COUNT FROM SHIPMENTS WHERE BLNUMBER <> '' AND CDATE > NOW() - INTERVAL 1 MONTH AND CDATE < NOW() - INTERVAL 7 DAY AND CONTAINERNUMBER <> '' AND CONTAINERNUMBER NOT LIKE '.AIR%' AND CONTAINERNUMBER NOT LIKE 'AIR%' AND CARRIER_ID <>8 AND STATUS = '' GROUP BY BLNUMBER HAVING COUNT > 1 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 所以,如果我正确理解这一点,您希望选择所有BLNUMBERS,其中每个CONTAINER都有一个空白的BLNUMBER,这意味着您希望排除至少有1个STATUS的BLNUMBERS,而不是空白的CONTAINER?为此,我将计算每个STATUS的CONTAINERs总数,然后用空白BLNUMBER计数每个CONTAINER的STATUSs总数,然后只返回总BLNUMBERs数等于空白BLNUMBERSs数的CONTAINER。所以SELECT totalBlanks.BLNUMBER, totalBlanks.`count`FROM (SELECT BLNUMBER, COUNT(*) `count` FROM SHIPMENTS GROUP BY BLNUMBER) totals LEFT JOIN (SELECT BLNUMBER, COUNT(*) `count` FROM SHIPMENTS WHERE `STATUS` = '' GROUP BY BLNUMBER) totalBlanks ON totals.BLNUMBER = totalBlanks.BLNUMBERWHERE totals.`count` = totalBlanks.`count` (adsbygoogle = window.adsbygoogle || []).push({});
09-25 21:02