首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带子查询的Couchbase

带子查询的Couchbase
EN

Stack Overflow用户
提问于 2022-07-27 12:59:43
回答 1查看 32关注 0票数 2

我将编写一个有子查询的案例,如下所示,但既不能输出,也不能输出错误:

代码语言:javascript
复制
select
case
when f.resGeo.isRural = true 
  then (select g.ID as geo_id
    from bktsample.scpPC.GeoInfo g 
    where g.PROVINCE_ID = f.resGeo.province.id 
     and g.CITYES_ID = f.resGeo.countie.id
     and g.PART_ID = f.resGeo.part.id
     and g.CITYORCOUNTRY_ID = f.resGeo.countie.id
     and g.VILLAGE_ID = f.resGeo.village.id)
when f.resGeo.isRural = false
  then (select g.ID 
    from bktsample.scpPC.GeoInfo g 
    where g.PROVINCE_ID = f.resGeo.province.id 
     and g.CITYES_ID = f.resGeo.countie.id
     and g.PART_ID = f.resGeo.part.id
     and g.CITYORCOUNTRY_ID = f.resGeo.countie.id) 
end as geo_id

from bktsample.scpPC.Family f;

PS: GEO是我的收藏,scpPC是我的范围,bktsample是我的桶。

EN

回答 1

Stack Overflow用户

发布于 2022-07-27 15:55:45

家族集合中的每个文档都应该返回一个geo_id文档(不是空数组就是ID对象)

对查询的小更改:

代码语言:javascript
复制
CREATE INDEX ix1 ON bktsample.scpPC.Family(resGeo.province.id, resGeo.countie.id, resGeo.part.id, resGeo.countie.id, resGeo.village.id, resGeo.isRural);
CREATE INDEX ix2 ON bktsample.scpPC.GeoInfo(PROVINCE_ID, CITYES_ID, PART_ID, CITYORCOUNTRY_ID, VILLAGE_ID, ID);

SELECT
    (SELECT g.ID AS geo_id
     FROM bktsample.scpPC.GeoInfo AS g
     WHERE g.PROVINCE_ID = f.resGeo.province.id
           AND g.CITYES_ID = f.resGeo.countie.id
           AND g.PART_ID = f.resGeo.part.id
           AND g.CITYORCOUNTRY_ID = f.resGeo.countie.id
           AND (f.resGeo.isRural == false OR g.VILLAGE_ID = f.resGeo.village.id))
    ) AS geo_ids
FROM bktsample.scpPC.Family f
WHERE f.resGeo.province.id IS NOT NULL; 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73138423

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档