如何选择两个列值之一不能为空的行?

发布于 2025-01-12 08:03:53 字数 369 浏览 1 评论 0原文

例如:

hive> select mid, tag1, tag2, dt from message_use_tags where dt="20211107" and (tag1 != '' or tag2 != 'NULL') limit 50;

我想指定:

  1. date = '20211107'

  2. tag1 和 tag2 不能同时为空字符串。其中之一可以为空。然而,以下并没有达到目的:

    tag1 != '' 或 tag2 != 'NULL'

在结果集中,存在 tag1 和 tag 均为空字符串的行。如何修改语句才能得到想要的结果?

For example:

hive> select mid, tag1, tag2, dt from message_use_tags where dt="20211107" and (tag1 != '' or tag2 != 'NULL') limit 50;

I want to specify:

  1. date = '20211107'

  2. tag1 and tag2 can't be both empty string at the same time. One of them can be empty. However, the following doesn't achieve the purpose:

    tag1 != '' or tag2 != 'NULL'

In the result set, there are rows where both tag1 and tags are empty strings. How to modify the statement to get the results desired?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三生路 2025-01-19 08:03:53
hive> select mid, tag1, tag2, dt from message_use_tags where dt="20211107" and (tag1 != '' or tag2 != 'NULL') and (tag1 != '' and tag2 != '') limit 50;
hive> select mid, tag1, tag2, dt from message_use_tags where dt="20211107" and (tag1 != '' or tag2 != 'NULL') and (tag1 != '' and tag2 != '') limit 50;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文