需求是这样的:需要找出没有发任务的店铺是哪些。好让客服去联系他们,询问情况。
每个商家可以有N个店铺,每个店铺可以放N个任务,一个任务会生成N个任务订单,会员接到任务去完成
SELECT *
FROM `keke_w_mall_shop`
WHERE shopid NOT
IN (
SELECT shopid
FROM (
SELECT shopid, kk, uid
FROM (
SELECT DISTINCT a.shopid, count( 1 ) AS kk, a.uid
FROM `keke_w_mall_shop` AS a
LEFT JOIN `keke_w_task_work` AS b
USING ( shopid )
WHERE b.op_status >0
GROUP BY b.shopid
) AS a
) AS p
WHERE 1 =1
)
用到了唯一,和子查询,和左关联查询