これは速いでしょう。関数から必要なものを正確に取得できませんrow_number()
。私が得るもの:
異なるを持つ異なる でrow_number()
のみインクリメントする必要があります。したがって、スクリーン キャップの行 4 ~ 9 はすべて 1 である必要があります。行 13 は 1 である必要があり (新しい patid であるため)、行 14 は 2 である必要があります (1 日あたりの投与量が変化したためです。得られるもの:patid
dailyDosage
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