sql - 如何在 SQL Server 中根据进程类型对数据进行分组?
问题描述
我必须将某些类型的数据分组到视图中的一行。我试过下面的查询:
select case when Process in ('A1','A2') then 'A'
when Process in ('C1','C2') then 'C'
else Process as p,max(StartDate),max(EndDate)
from t
group by case when Process in ('A1','A2') then 'A'
when Process in ('C1','C2') then 'C'
else Process
表数据:
| Process | Date | Comment |
+-----------+-----------+-----------+
| A1 | 05-06-2018| Submitted |
| A2 | 07-03-2018| Approved | --Here A1 & A2 are same process
| B1 | 03-02-2018| Pending |
| C1 | 07-06-2018| Submitted |
| C2 | 09-25-2018| Pending | --Here C1 & C2 are same process
期望的输出:
| Process | StartDate | EndDate | Comments |
+-----------+-----------+--------------+----------------------+
| A | 05-06-2018| 07-03-2018 | Submitted ; Approved |
| B | 03-02-2018| 03-02-2018 | Pending |
| C | 07-06-2018| 09-25-2018 | Submitted ; Pending | |
解决方案
推荐阅读
- javascript - 如何使用类似于 Laravel 的 Artisan 的终端从模板生成 JavaScript?
- r - 将矩阵的一列转换为美元
- vue.js - 用于标题大小写的 Vue JS 过滤器
- javascript - 隐藏和显示 div 不起作用,当我使用 console.log() 但不显示时,元素会更改其属性
- machine-learning - 为什么不同的股票可以合并在一起建立一个单一的预测模型?
- javascript - 待办事项编辑功能
- php - PHP数组排序前3名
- math - 四元数到矩阵只旋转一个轴
- gradle - 在模块中找到重复的类
- javascript - 如何禁用
- 使用 ng-class 标记?