我正在尝试使用以下代码创建一条将语句添加几天到CURDATE的select语句:

      SELECT
                po.factory,
                po_item.po,
                po_item.style,
                po_item.style_name,
                po_item.customer_style,
                po_item.colors,
                po_item.material,
                po_item.pairs,
                po.sef,
                po.client,
                ROUND(((po_item.pairs)/12)) as total_ctn,
                style.shoe_dimension,
                factory.official_name,
            DATE_FORMAT(CURDATE()+10, '%m/%d/%y') as FROMTHIS,
            DATE_FORMAT(CURDATE()+17, '%m/%d/%y') as TOTHIS,
            CASE WHEN
                po.rlsd is not null THEN po.rlsd ELSE po.lsd END AS date
            FROM
                po_item
                inner join po on
                    po_item.po = po.po
                inner join factory on
                    po.factory = factory.id
                      inner join style on po_item.style = style.style
                      inner join client on po.client = client.id
                      inner join divisions on client.division = divisions.id
            WHERE
                divisions.group_division_id = '19'
                AND po.ref is null
                AND po.status != 'C'
            ORDER BY
                po.cls DESC


这是怎么回事:

mysql - SQL选择日期范围明年发行-LMLPHP

    DATE_FORMAT(CURDATE()+10, '%m/%d/%y') as FROMTHIS,
    DATE_FORMAT(CURDATE()+17, '%m/%d/%y') as TOTHIS,


都返回{null},因为这是明年的日期,因为CURDATE(today)等于2017/12/10 +12应该是2018/01/01,但返回为{null}

有谁知道如何解决?
谢谢

然后,我想在where语句中都使用它们,例如:

      SELECT
                po.factory,
                po_item.po,
                po_item.style,
                po_item.style_name,
                po_item.customer_style,
                po_item.colors,
                po_item.material,
                po_item.pairs,
                po.sef,
                po.client,
                ROUND(((po_item.pairs)/12)) as total_ctn,
                style.shoe_dimension,
                factory.official_name,
                DATE_FORMAT(po.cls, '%m/%d/%y') AS date_cls,
                DATE_FORMAT(CURDATE(), '%m/%d/%y') as date_today,
                DATE_FORMAT(CURDATE()+10, '%m/%d/%y') as audit,
            DATE_FORMAT(DATE_ADD(CURDATE(),INTERVAL 12 DAY), '%m/%d/%y') AS FROMTHIS,
            DATE_FORMAT(DATE_ADD(CURDATE(),INTERVAL 17 DAY), '%m/%d/%y') AS TOTHIS,
            CASE WHEN
                po.rlsd is not null THEN po.rlsd ELSE po.lsd END AS date
            FROM
                po_item
                inner join po on
                    po_item.po = po.po
                inner join factory on
                    po.factory = factory.id
                      inner join style on po_item.style = style.style
                      inner join client on po.client = client.id
                      inner join divisions on client.division = divisions.id
            WHERE
                po.cls BETWEEN `FROMTHIS` AND `TOTHIS`
                AND divisions.group_division_id = '19'
                AND po.ref is null
                AND po.status != 'C'
            ORDER BY
                po.po,
                po.cls DESC


但不起作用

最佳答案

请尝试以下查询:

SELECT DATE_FORMAT(DATE_ADD(CURDATE(),INTERVAL 10 DAY), '%m/%d/%y') AS FROMTHIS
SELECT DATE_FORMAT(DATE_ADD(CURDATE(),INTERVAL 17 DAY), '%m/%d/%y') AS TOTHIS

08-08 01:37