我一直在尝试获取状态,因此我可以找出错误更改其状态“已解决”需要多长时间,因此我有以下 SQL:
select bug.id,
bug.project_id,
DATEDIFF (FROM_UNIXTIME(his.date_modified), FROM_UNIXTIME(date_submitted)) as dias_resolucao,
DATE_FORMAT(FROM_UNIXTIME(his.date_modified), '%Y-%m') as ano_mes
from mantis_bug_table bug
left join mantis_project_table pro on bug.project_id = pro.id
left join mantis_custom_field_string_table cus on bug.id = cus.bug_id
left join mantis_bug_history_table his on bug.id = his.bug_id
where bug.category_id = 1 and
(cus.field_id=1 or cus.field_id is null) and
his.new_value = 80 and
his.field_name = 'status' and
bug.id = 5171 and
cus.value='Sim'
having his.date_modified = max(his.date_modified)
问题是我不知道为什么会打印以下错误:
[SELECT - 0 row(s), 0.000 secs]
[Error Code: 1054, SQL State: 42S22]
Unknown column 'his.date_modified' in 'having clause'
运行相同的 SQL,但不使用 have 子句,我会得到以下结果:
╔══════╦════════════╦════════════════╦═════════╗
║ id ║ project_id ║ dias_resolucao ║ ano_mes ║
╠══════╬════════════╬════════════════╬═════════╣
║ 5171 ║ 4 ║ 17 ║ 2012-12 ║
║ 5171 ║ 4 ║ 18 ║ 2012-12 ║
╚══════╩════════════╩════════════════╩═════════╝
任何帮助表示赞赏。