MySQL GROUP BY NULL 和 EMPTY
在 MySQL 查询中,我使用文本字段执行GROUP BY
。由于原始数据的性质,某些行包含此字段的空字符串,而其他行则为 true null
。
分组时,如何将空字符串和 null 分组在一起,将两者视为 null
?
In a MySQL query I am doing a GROUP BY
with a text field. Due to the nature of the original data, some rows are contain empty strings for this field, and others are true null
.
When grouping, how can I group empty string and null together, treating both as null
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可以通过 SELECT CASE 来完成。可能有一种我不知道的更简单的方法。
SELECT CASE 的格式是
所以你看,你可以用 WHEN/THEN 将值 CASE 在一起,并用 ELSE 默认为实际值。
This can be accomplished by SELECT CASE. There may be a simpler way I do not know of.
The format of SELECT CASE is
So you see, you can CASE together values with WHEN/THEN and default to the real value by ELSE.