这个会很快。我无法从函数中得到我想要的东西row_number()
。我得到什么:
我row_number()
只需要在patid
具有不同dailyDosage
. 所以屏幕帽上的第 4-9 行应该都是 1。第 13 行应该是 1(因为它是一个新的 patid),第 14 行应该是 2(因为每日剂量的变化。我得到:
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