sql - 旋转重复项的最佳方法是什么?
解决方案
您可以使用row_number()
条件聚合:
select key,
max(case when rn = 1 then email end) email1,
max(case when rn = 2 then email end) email2,
max(case when rn = 3 then email end) email3
from (
select t.*, row_number() over(partition by key order by email) rn
from mytable t
) t
group by key
您可以在子句中添加更多条件max()
s 以select
处理超过 3 email
s per key
。
推荐阅读
- pyspark - PySpark - 从字符串生成 StructType
- email - Seblod 如何影响 Joomla 中的授权工作
- php - 如何在 Debian 9 上安装 pthreads PHP 扩展
- c# - 为什么数据没有插入到 SQL 数据库中
- angular - Ngrx 中的 Rxjs - 在过滤器/副作用结束后调用操作
- scala - 连接数据上的复杂数据类型实现
- python - 如何打包 tensorflow-gpu 模型在大多数机器上运行?
- javascript - 为什么这个 MongoDB 错误函数不能正常工作?
- javascript - 离子4中的(按键)事件未触发
- avfoundation - 无法在 iOS 13 beta 3 模拟器上播放 AES-128 加密的 HLS 视频流