解释起来有点困难,我不知道如何在具有分组依据和聚合函数的 SQL 中的列选择属性中使用条件...
会议 | 开始日期 | 日期结束 | 交易ID | 贸易KP |
---|---|---|---|---|
1 | 2024-12-09 11:20:15.000 | 2024-12-09 11:20:16.000 | tr1 | ICM |
1 | 2024-12-09 11:20:07.000 | 2024-12-09 11:20:48.000 | tr53 | 信息通信技术 |
1 | 2024-12-09 11:22:07.000 | 2024-12-09 11:24:48.000 | . | ICM |
2 | 2024-12-08 04:55:09.000 | 2024-12-08 04:55:11.000 | jik67 | SMC |
2 | 2024-12-08 04:55:13.000 | 2024-12-08 04:55:38.000 | . | 产品生命周期管理 |
我想返回会话分组:
示例:
会议 | 开始 | 完结 | 交易大师 |
---|---|---|---|
1 | 2024-12-09 11:20:07.000 | 2024-12-09 11:24:48.000 | ICM |
2 | 2024-12-08 04:55:09.000 | 2024-12-08 04:55:38.000 | 产品生命周期管理 |
我尝试了这个请求,但它不起作用:
SELECT session,
MIN(DateStart) as beginning,
MAX(DateEnd) as ending,
MAX(tradeKP) as TradingMaster
FROM SCHEMA.TRADES
GROUP BY session
尝试
SELECT session,
MIN(DateStart) as beginning,
MAX(DateEnd) as ending,
MAX(case when tradeID='.' then tradeKP end) as TradingMaster
FROM SCHEMA.TRADES
GROUP BY session