編號 顏色 序號
1 黑色 3-1
2 紅色 2-1
3 藍色 1-1
4 黑色 3-2
5 黑色 3-3
6 紅色 2-2
序號的意思比如黑色一共3個,
編號1是三缸布當中的第1缸 所以是3-1
編號4是三缸布當中的第2缸 所以是3-2
編號5是三缸布當中的第2缸 所以是3-3
uj5u.com熱心網友回復:
with t as (
select 1 as id,'黑色' as color
union all select 2,'紅色'
union all select 3,'藍色'
union all select 4,'黑色'
union all select 5,'黑色'
union all select 6,'紅色'
)
select *,convert(varchar,cnt)+'-'+CONVERT(varchar,rid) as sn
from (
select *,ROW_NUMBER() over(partition by color order by id) as rid
from t
) a
cross apply (
select COUNT(0) as cnt from t where color=a.color
) b
order by id
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/280107.html
標籤:基礎類
上一篇:我想用html js寫
