2

これは速いでしょう。関数から必要なものを正確に取得できませんrow_number()。私が得るもの: ここに画像の説明を入力

異なるを持つ異なる でrow_number()のみインクリメントする必要があります。したがって、スクリーン キャップの行 4 ~ 9 はすべて 1 である必要があります。行 13 は 1 である必要があり (新しい patid であるため)、行 14 は 2 である必要があります (1 日あたりの投与量が変化したためです。得られるもの:patiddailyDosage

select distinct 
     ROW_NUMBER() over(partition by rx.patid,quantity/daysSup*cast(REPLACE(LEFT(strength,PATINDEX('%[^0-9]%',strength)),'m','') as int) 
     order by rx.patid,quantity/daysSup*cast(REPLACE(LEFT(strength,PATINDEX('%[^0-9]%',strength)),'m','') as int))
     ,rx.patid
    ,rx.drugName
    ,rx.strength
    ,rx.quantity
    ,rx.daysSup
    ,rx.fillDate
    ,quantity/daysSup*cast(REPLACE(LEFT(strength,PATINDEX('%[^0-9]%',strength)),'m','') as int) as dailyDosage
    from rx 
    inner join (select distinct m.patid, m.sex, m.injurylevel from members as m) as m on m.PATID=rx.patid
    where ISNUMERIC(REPLACE(LEFT(strength,PATINDEX('%[^0-9]%',strength)),'m',''))=1 
    and REPLACE(LEFT(strength,PATINDEX('%[^0-9]%',strength)),'m','') not like '%.%' 
    and drugname in ('baclofen')
    and daysSup !=0 and quantity !=0
    and daysSup > 1
    order by rx.patid

SQL Server 2008 R2

4

2 に答える 2

6

あなたは毎日の投与量をランク付けしようとしていると思います. dense_rankではなく使ってみてくださいrow_nubmer

Row_number は行を列挙します。ランクは同じ値をまとめて保持します。Dense_rank は列挙を行い、最初のグループ 1 を割り当て、次のグループ 2 などを割り当てます。ランクはナンバリングにギャップを残します。

于 2012-11-13T20:16:24.280 に答える
5

を変更してROW_NUMBER使用する必要がありますRANK

于 2012-11-13T20:14:15.587 に答える