【问题标题】:Strange where clause behavior with upper(string) in ('str1','str2','str3')('str1','str2','str3') 中带有 upper(string) 的奇怪 where 子句行为
【发布时间】:2020-11-14 15:52:24
【问题描述】:

当我运行代码时

SELECT * FROM tbl
WHERE
date BETWEEN '20200520' and '20200520' 
and country_id in ('US','us','USA')

--and upper(country_id) in ('US''JP','IN','GB','CA')
and app_id in (1180,1233)
LIMIT 5

我得到如下结果

但是,如果我在下面添加 where 子句,则不会返回任何数据。

SELECT * FROM
    tbl
WHERE
date BETWEEN '20200520' and '20200520' 
and country_id in ('US','us','USA')
and upper(country_id) in ('US''JP','IN','GB','CA')
and app_id in (1180,1233)
LIMIT 5

不应该返回('US'和'us')中带有country_id的记录吗?这里有什么问题?

提前致谢。

【问题讨论】:

标签: sql string hive where-clause uppercase


【解决方案1】:

使用 or 代替 and

SELECT * FROM
    tbl
WHERE
date BETWEEN '20200520' and '20200520' 
and (country_id in ('US','us','USA')
or upper(country_id) in ('US','JP','IN','GB','CA')
)
and app_id in (1180,1233)
LIMIT 5

【讨论】:

    【解决方案2】:

    你少了一个逗号。

    和upper(country_id) in ('US''JP','IN','GB','CA')

    【讨论】:

      猜你喜欢
      • 2010-09-06
      • 2010-09-16
      • 1970-01-01
      • 2017-03-29
      • 1970-01-01
      • 2014-10-22
      • 1970-01-01
      • 1970-01-01
      • 2013-04-27
      相关资源
      最近更新 更多