根据他们的患者是否在分子中,我们对提供者有分数。为了完成对患者是否设置(合规或不合规)的验证,我的任务是创建一个报告,从每个指标中随机选择50个患者。现在,我可以运行我的查询12次,为每个指标收集50名患者,但这非常耗时。我考虑过将代码从Top 50更改为Top 600,但返回600个随机行,但并未表示所有指标。
我所包含的代码是一次只为一个指标编写的代码。
DECLARE
@MetricID INT
,@AsOfDate DATE
SET @MetricID = 52
SET @AsOfDate = '04/30/2017'
SELECT TOP 50
Pat.PatientID
,Metrics.MetricID
,Metrics.MetricName
,PCPS.NumCompliant
,Denominator = PCPS.PQRIPopulation
,AsOfDate = PCPS.EndDate
FROM
dbo.PhyComPQRSStaging PCPS TABLESAMPLE(.2 PERCENT)
INNER JOIN dbo.PCQMPatient Pat
ON PCPS.PATIENTID= Pat.PATIENTID
INNER JOIN dbo.PCQMMetrics Metrics
ON PCPS.MetricID = Metrics.MetricID
WHERE
Metrics.MetricID = @MetricID
GROUP BY
Pat.PAT_ID
,Pat.FH_MRN
,PAMN.AlternateMeasureNumber
,Metrics.MetricID
,Metrics.MetricName
,PCPS.NumCompliant
,PCPS.PQRIPopulation
,PCPS.EndDate
我确信有可能在SQL之外执行此操作,但我仅限于此时仅使用SQL。非常感谢任何帮助。
答案 0 :(得分:4)
这是你可以做到这一点的一种方法。这是使用ROW_NUMBER并随机排序结果,因此每次运行时结果都会不同。
WITH SortedResults AS
(
SELECT
Pat.PatientID
,Metrics.MetricID
,Metrics.MetricName
,PCPS.NumCompliant
,Denominator = PCPS.PQRIPopulation
,AsOfDate = PCPS.EndDate
, ROW_NUMBER() OVER(PARTITION BY Pat.PatientID, Metrics.MetricID ORDER BY (SELECT NEWID())) AS RowNum
FROM
dbo.PhyComPQRSStaging PCPS TABLESAMPLE(.2 PERCENT)
INNER JOIN dbo.PCQMPatient Pat
ON PCPS.PATIENTID= Pat.PATIENTID
INNER JOIN dbo.PCQMMetrics Metrics
ON PCPS.MetricID = Metrics.MetricID
WHERE
Metrics.MetricID = @MetricID
GROUP BY
Pat.PAT_ID
,Pat.FH_MRN
,PAMN.AlternateMeasureNumber
,Metrics.MetricID
,Metrics.MetricName
,PCPS.NumCompliant
,PCPS.PQRIPopulation
,PCPS.EndDate
)
SELECT sr.PatientID
, sr.MetricID
, sr.MetricName
, sr.NumCompliant
, sr.Denominator
, sr.AsOfDate
FROM SortedResults sr
WHERE sr.RowNum <= 50