Mysql 查询列时 合并多列的函数COALESCE

查询时遇到需要查一周内参与了PK的主播数,而PK记录表有发起人和对方ID两列,所以需要对两列合并然后记不重复数量
userId 是发起人ID,objId是PK对方ID

函数COALESCE可传入多列合并后进行操作

select count(distinct COALESCE(userId,objId)) from PKSessionHistory where createTime >= '2022-11-28 16:00:00' and createTime  <= '2022-12-04 23:59:59' and totalScore >= 50  
posted @ 2022-12-05 14:22  HumorChen99  阅读(3)  评论(0编辑  收藏  举报  来源