我有一个提取数据的查询。这是我的WHERE
条款。
where p.invc_dt BETWEEN 1150101 AND 1160131
and o.Tracking_num is not null
此表包含订单数据和ORDER_CD
列,用于标识销售类型或是否已退款。退款不关联跟踪号。我怎样才能调整我的where语句来说出像
and o.Tracking_num is not null **unless** `ORDER_CD` is REFUND
答案 0 :(得分:1)
您可以使用布尔逻辑实现逻辑:
where p.invc_dt BETWEEN 1150101 AND 1160131 and
(o.Tracking_num is not null or order_cde = 'REFUND')
我不确定“除非”是否属于排他性,所以你可能意味着:
where p.invc_dt BETWEEN 1150101 AND 1160131 and
((o.Tracking_num is not null and order_cde <> 'REFUND')
(o.Tracking_num is null and order_cde = 'REFUND')
)
答案 1 :(得分:1)
where p.invc_dt BETWEEN 1150101 AND 1160131
and ( o.Tracking_num is not null OR `ORDER_CD` = 'REFUND' )