任务是获取有超过 2 个不同特殊代码的订单代码列表,现在我已经有了这个查询
SELECT
o.id AS iOrderId,
o.code AS sOrderCode,
oa.pnr AS sSpecialCode
FROM
order_air AS oa
JOIN
orders AS o ON 1
AND oa.order_id = o.id
WHERE 1
AND o.status = 11
AND oa.issued = 1
AND oa.change_status != 0
AND oa.issued_date BETWEEN NOW() - INTERVAL 12 MONTH AND NOW()
GROUP BY o.id
HAVING COUNT(*) >= 2
LIMIT 20
它还给我
一切都很好,但是这个查询不检查不同的特殊代码,只是返回所有超过 2 个特殊代码的订单代码。我也尝试过查看 IF 以保存以前的 orderid,然后通过它进行检查,但我不知道如何将以前的 id 存储到 @prev 之类的东西中,所以这对我没有帮助,任何想法如何正确过滤这个队列?