0

任何人都可以帮助我将以下查询转换为现在正在使用 postgresql 的 mssql

查询是按日期的升序获取报告的更新日期时间

select 
count(*) as count, 
TO_CHAR(RH.updated_datetime,'dd-mm-YYYY') as date,
SUM( 
  extract ( 
    epoch from ( 
      RH.updated_datetime - PRI.procedure_performed_datetime 
    )
  )
)/count(*) as average_reporting_tat 
from 
report R, 
report_history RH, 
study S, 
procedure_runtime_information PRI, 
priorities PP, 
patient P, 
procedure PR 

where 

RH.report_fk=R.pk and RH.pk IN ( 
  select pk from ( 
    select * from report_history where report_fk=r.pk order by revision desc limit 1 
  ) as result 
  where old_status_fk IN (21, 27)
) AND R.study_fk = S.pk 
AND S.procedure_runtime_fk = PRI.pk 
AND PRI.procedure_fk = PR.pk 
AND S.priority_fk = PP.pk 
AND PRI.patient_fk = P.pk 
AND RH.updated_datetime >= '2013-05-01' 
AND RH.updated_datetime <= '2013-05-12' 
group by date
4

1 回答 1

1

如果我正确阅读了您的查询,您的问题是您需要在列列表中的 group by 子句中列出所有内容,该子句不是聚合的一部分。所以你的 group by 需要是:

GROUP BY RH.updated_datetime

如果这不能解决问题,请发布您收到的错误消息。

于 2013-10-26T09:40:53.037 回答