0

我有两个值,一个 InvoiceDate(格式:YYYY-MM-DD)和一个 WarrantyPeriod(格式:nn)(保修年数)

一个简单的查询来选择保修已过期的项目?

我试过这个:

SELECT
*
FROM
(
    SELECT
        UNIX_TIMESTAMP(DATE_FORMAT(item_invoice_date, '%Y-%m-%d %H:%i:%s')) AS ux_id,
        (item_warranty_period * 365 * 86400) AS ux_wp
    FROM
        items
    WHERE
        items.item_warranty_period > 0
    AND
        items.item_invoice_date != '0000-00-00'
) wd
,items
WHERE
items.item_warranty_period > 0
AND
items.item_invoice_date != '0000-00-00'
AND
wd.ux_id - wd.ux_wp < UNIX_TIMESTAMP(NOW())
GROUP BY
items.item_id

但似乎没有工作

4

2 回答 2

1
SELECT
  *
FROM
  items
WHERE
  NOW() > (invoice_date + INTERVAL warranty_period YEAR)
于 2013-09-01T11:42:34.313 回答
0

我没有真正得到你想要的查询,但你在寻找这个吗?

SELECT * FROM table WHERE ADDDATE(InvoiceDate, INTERVAL WarrantyPeriod YEAR) < NOW()

见:http ://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

于 2013-09-01T11:43:14.530 回答