請教下各位老師,現在我有兩列資料,資料格式如下:
id price
1 100
1 100
1 100
1 80
2 100
2 100
2 50
3 150
3 60
我想通過sas陳述句計算在同一個id下,(第一條資料的price)-(最后一條資料的price)/(第一條資料的price)
例如在id=1 的時候,求(100)-(80)/100
想請教一下各位老師,應該作何表達?
uj5u.com熱心網友回復:
請問有人能幫我看一下么uj5u.com熱心網友回復:
create table #t(id int , price int)
insert into #t
select 1,100 union all
select 1,100 union all
select 1,100 union all
select 1,80 union all
select 2,100 union all
select 2,100 union all
select 2,50 union all
select 3,150 union all
select 3,60
;with cte as(
select *, row_number() over(partition by id order by id) as rn from #t
)
select id, (min(price)-max(price))/min(price)*1.000 as rate from cte
group by id,price,rn
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/196304.html
標籤:疑難問題
上一篇:求哪位大佬幫幫忙
