我正在尝试进行查询,其中一个字段显示明天计划的订单表的单位,但是如果明天是星期日,则应该是星期一。

我有表顺序和表格式。

订单表:
id_order,order_date,单位

格式表:
id_format,format_type

我的查询最初是这样的:

SELECT format_type, units, DATE (NOW () + INTERVAL 1 DAY) as Tomorrow
FROM orders Join format on orders.id_format = format.id_format
WHERE DATE (date_delivery) = DATE (NOW () + INTERVAL 1 DAY)


但这必须是类似的东西:

SELECT format_type, units, DATE (NOW () + INTERVAL 1 DAY) as Tomorrow
FROM orders Join format on orders.id_format = format.id_format
WHERE (
  CASE
  WHEN DAYNAME (date) = "Sunday" THEN DATE (order_date) = DATE (NOW () + INTERVAL 2 DAY)
  ELSE DATE (order_date) = DATE (NOW () + INTERVAL 1 DAY)
  END;


_____编辑_____

这是我想要的结果

SELECT format.format_type, units, DATE(NOW()) as TODAY
FROM orders Join format on orders.id_format = format.id_formatopeso
WHERE
  CASE
    WHEN WEEKDAY(now()) = 6 then DATE(order_date) = DATE(NOW() + INTERVAL 2 DAY)
    ELSE DATE(order_date) = DATE(NOW() + INTERVAL 1 DAY)
END;

最佳答案

Yuu可以简单地选择您在哪里拥有的东西

  SELECT format_type, units,
      CASE
        WHEN  WEEKDAY(date) = 6
            then DATE_ADD(curdate(), INTERVAL +2  DAY)
            else DATE_ADD(curdate(), INTERVAL +1  DAY)
        END as tomorrow_with_sunday_check,
      DATE_ADD(curdate(), INTERVAL +1  DAY) as Tomorrow
  FROM orders Join format on orders.id_format = format.id_format

关于mysql - 计算明天的日期,如果是星期天,则再显示两天-MySQL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47291815/

10-09 00:50