postgresql到mssql查询转换

时间:2013-06-14 11:29:35

标签: sql-server-2008 postgresql postgresql-9.1 postgresql-9.2

任何人都可以帮我将以下查询转换为mssql,现在正在postgresql上工作

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

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

1 个答案:

答案 0 :(得分:1)

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

GROUP BY RH.updated_datetime

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