其中 column.a 不为空,除非 column.b = 值

where column.a is not null unless column.b = value

我有一个查询正在提取一些数据。这是我的 WHERE 子句。

where p.invc_dt  BETWEEN 1150101 AND 1160131    
and o.Tracking_num is not null 

此 table 包含订单数据,以及一个 ORDER_CD 列来标识销售类型或是否退款。退款 没有 关联的追踪号码。我怎样才能调整我的 where 语句来说

and o.Tracking_num is not null **unless** `ORDER_CD` is REFUND

您可以使用布尔逻辑实现逻辑:

where p.invc_dt  BETWEEN 1150101 AND 1160131 and
      (o.Tracking_num is not null or order_cde = 'REFUND')

我不确定 "unless" 是否是排他性的,所以你的意思可能是:

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')
      )
where p.invc_dt  BETWEEN 1150101 AND 1160131    
and ( o.Tracking_num is not null OR `ORDER_CD` = 'REFUND' )