【问题标题】:How to skip null records in Orientdb while using group by clause如何在使用 group by 子句时跳过 Orientdb 中的空记录
【发布时间】:2016-02-22 12:29:27
【问题描述】:

当我执行以下查询时:

SELECT count(*) as count, $new_source as name 
from news 
LET $new_source = if(eval("source.indexof('Other') === 0"), "Other", source)
where country_id = "111111"
group by $new_source

它抛出一个错误说:

com.orientechnologies.orient.core.exception.OCommandExecutionException: 无法解析表达式项“源”,因为当前记录是 空

如果在“新闻”类中给定的 country_id 至少有一条记录,则效果很好,但如果给定的 country_id 没有记录,则抛出此错误。

由于我对所有新闻记录使用通用查询,而不考虑国家/地区 ID,因此如果特定国家/地区没有记录,我希望返回空记录集。

我也尝试过使用 orientdb 的 ifnull 函数来跳过空值,如下所示:

SELECT count(*) as count, $new_source as name from news LET $new_source = ifnull(source, 0, if(eval("source.indexof('Other') === 0"), "Other", source)) where country_id = "111111" group by $new_source

但它不工作,并抛出同样的错误。

我正在使用 OrientDb 2.1.8。我不想使用 javascript 函数并从控制台调用它(建议 here

有什么办法,我可以在使用 if with group by 时跳过空值?

【问题讨论】:

标签: orientdb orientdb-2.1


【解决方案1】:

我尝试修改您的查询,也许我找到了解决方案:

select count(*) as count,name
from (
  select if(eval("source.indexof('Other') === 0"), "Other", source) as name 
  from news where country_id = "111111")  
group by name

我没有错误,也没有正确的结果。

select count(*) as count,name
from (
  select if(eval("source.indexof('Other') === 0"), "Other", source) as name 
  from news where country_id = "1110")  
group by name

这里我有正确的结果

希望对你有帮助。

【讨论】:

    【解决方案2】:

    这应该可以解决您的问题:

    删除您的索引并使用引擎 Lucene 重新创建另一个全文类型的索引。

    查询你得到这个结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-16
      相关资源
      最近更新 更多