求sql server写法

solidvacuum 2023-12-28 22:22:25

 如图,想把图一写成图二格式,怎么写,求大神

 

...全文
326 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
CSDN-Ada助手 2023-12-28
精选
  • 打赏
  • 举报
回复
您的问题已经帮您同步至问答, 链接: https://ask.csdn.net/questions/8051708, 请您保持关注, 如果回答有帮助解决此问题, 麻烦您动动小手给相关的回答点赞, Ada会在评论区为您更新结题状态
河狸吗 2023-12-30
  • 打赏
  • 举报
回复

declare @tmp table(pid varchar(10),cid varchar(20))

insert into @tmp(pid,cid)
select '0','42032-0001' union all
select '.1','42032-0001-001' union all
select '..2','1041-0261' union all
select '...3','30328-0102-0001' union all
select '0','52032-0001' union all
select '.1','42032-0001-001' union all
select '..2','1041-0261' union all
select '...3','30328-0102-0001'

;with t1 as (
select ROW_NUMBER() over(partition by pid order by pid) as rowid,pid,cid
from @tmp
),t2 as (
select ROW_NUMBER() over(partition by pid order by pid) as rowid,pid,cid
from @tmp where pid = '0'
)
select t2.cid as pid,t1.cid
from t1 left join t2 on t1.rowid = t2.rowid
order by t2.cid

原子星 2023-12-29
  • 打赏
  • 举报
回复

update 表名 set pid=left(cid,10)

17,382

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧