MYSQL 加入表格并选择特定日期没有订单的客户

MYSQL joining tables and selecting customer with no order for particular date

我在处理此 mysql 查询时遇到问题。我有一个客户 table 和一个订单 table,由客户 ID 链接。订单 table 有一个日期字段,我试图列出在特定月份(2016 年 7 月)没有任何订单的客户的姓名。有人告诉我 NOT IN 可能有帮助,但我不知道该怎么做。我寻找了类似的例子,但他们使用 IS NULL。我试过了,但它不喜欢 NOT(在此位置不是有效输入:

SELECT customer.cust_name FROM customer LEFT JOIN ordertbl ON ordertbl.cust_id = customer.cust_id WHERE order_date like '2016-07%' not in ordertbl.order_date;

然后我尝试了这个,但没有返回任何结果:

SELECT customer.cust_name FROM customer LEFT JOIN ordertbl ON ordertbl.cust_id = customer.cust_id WHERE (SELECT COUNT(order_date like '2016-07%')) IS NULL;

我也找了一个类似的例子但是拿不到,没有结果:

Select customer.cust_name From customer where ordertbl.cust_id Not in ( Select customer.cust_id From ordertbl Where ordertbl.order_date like '2016-07%');

我确定我做错了。我尝试了其他几个例子,但那些也没有用。感谢任何帮助。

假设在订单 table 中,您的客户 ID 参考名为 CUSTOMER_ID,查询为:

SELECT CUSTOMER.CUST_NAME
    FROM CUSTOMER
    WHERE CUST_ID IN
        (SELECT ORDERTBL.CUSTOMER_ID 
        FROM ORDERTBL
        WHERE DATE <> yourdate)