mysql 查询某个值非空,分组后,MySQL获得第一个非空值

在处理包含重复电子邮件但需要唯一化的大型数据表时,遇到问题。当使用GROUP BY email时,某些记录的名字显示为NULL。尝试使用GROUP_CONCAT导致每一行的名称被连接。目标是为每个邮件组选择第一行的非空名称。MAX函数提供了解决方案,如:SELECT email, MAX(name) FROM (SELECT email, name FROM multiple_tables_and_unions) AS emails GROUP BY email。" 119363024,1433559,MUI登录页面美化实战,"['HTML', 'CSS', 'JavaScript', '前端开发']
摘要由CSDN通过智能技术生成

I have a large table with data that is not unique but needs to be. This table is a result of multiple union selects so is not an actual table. I cannot make it an actual table for other reasons.

All of the UNION'd tables have an email column which will eventually be unique. The resulting records look like this:

1 ozzy@test.com Ozzy

2 test@test.com Tony

3 test@yahoo.com Steve

4 tiny@test.com

13 tony@gmail.com Tony

14 test@test.com Ozzy

15 test@yahoo.com Dave

16 tiny@test.com Tim

As you can see, some emails appear more then once with different names or non existent names. When I add a GROUP BY email clause at the end, the results look like this:

1 ozzy@test.com Ozzy

2 test@test.com Tony

3 test@yahoo.com Steve

4 tiny@test.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值