我正在尝试执行以下mySQL查询:

SELECT
    SQL_CALC_FOUND_ROWS,
    TIMESTAMPDIFF(DAY, date_identified,
    IFNULL(date_closed,
    CURDATE())) as days_open,
    *
FROM (`risks`)
ORDER BY `WBS` ASC LIMIT 10


但我一直出错。但是,如果我删除SQL_CALC_FOUND_ROWS*而改为:

SELECT
    id, TIMESTAMPDIFF(DAY, date_identified,
    IFNULL(date_closed,
    CURDATE())) as days_open
FROM (`risks`)
ORDER BY `WBS` ASC LIMIT 10


然后查询成功执行。有什么办法可以更改此查询以包含SQL_CALC_FOUND_ROWS*

最佳答案

我可以想到的最简单的方法是在*之前包括行源名称(或别名):

SELECT SQL_CALC_FOUND_ROWS
    TIMESTAMPDIFF(DAY, date_identified, IFNULL(date_closed, CURDATE())) as days_open,
    `risks`.*
FROM
    (`risks`)
ORDER BY
    `WBS` ASC
LIMIT 10

10-04 10:56