0

私はステータスを取得しようとしてきたので、バグの変更にどれくらいの時間がかかっているかを知ることができ、そのステータスは「解決済み」なので、次の 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'

having 句なしで同じ SQL を実行すると、次の結果が得られます。

╔══════╦════════════╦════════════════╦═════════╗
║  id  ║ project_id ║ dias_resolucao ║ ano_mes ║
╠══════╬════════════╬════════════════╬═════════╣
║ 5171 ║          4 ║             17 ║ 2012-12 ║
║ 5171 ║          4 ║             18 ║ 2012-12 ║
╚══════╩════════════╩════════════════╩═════════╝

どんな助けでも大歓迎です。

4

2 に答える 2

2

それを試してみてください。

SELECT his.date_modified, 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)
于 2013-04-09T13:31:20.150 に答える