梁凉凉 2023-02-13 11:08 采纳率: 100%
浏览 35
已结题

根据“creatDate”升序排序,“type”是“新增”的,“新增列”+“苹果”;如果“type”是“删除”的,“新增列”-“苹果”。不用游标

初始数据:

img


想要的结果数据:

img


需求:
根据“creatDate”升序排序,“type”是“新增”的,“新增列”+“苹果”;如果“type”是“删除”的,“新增列”-“苹果”。不用游标

  • 写回答

2条回答 默认 最新

  • bekote 2023-02-13 17:32
    关注

    假设表名为test

    
    select distinct(b.creatDate),stuff((select ',' + a.name from test a where a.type = '新增' and b.creatDate >= a.creatDate and not exists(select 1 from test c where c.creatDate <= b.creatDate and c.creatDate >= a.creatDate and c.type = '删除' and c.name = a.name) for xml path('')),1,1,'') as addData from test b
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 2月22日
  • 已采纳回答 2月14日
  • 创建了问题 2月13日