NLPchina / elasticsearch-sql

Use SQL to query Elasticsearch
Apache License 2.0
6.99k stars 1.54k forks source link

可以实现这类嵌套查询吗 #360

Open jecyyu opened 7 years ago

jecyyu commented 7 years ago

需要满足的语句是: select from ( select media,province,age,sex,count()as counts from mahad where sex in ('02401') GROUP BY media,province,age,sex)

yangsishu commented 7 years ago

嵌套子查询现在好像不支持

shi-yuan commented 7 years ago

As far as I know, elasticsearch doesn't support subqueries. you would need to perform your first query, then construct a second query using the results of the first query as an input

treecy commented 7 years ago

@shi-yuan Sorry, but could I ask how to use the results as an input? Like temporary table or something?

shi-yuan commented 7 years ago
SELECT * FROM test/dog WHERE holdersName IN (SELECT firstname FROM test/account WHERE firstname = 'Hattie') AND age IN (SELECT name.ofHisName FROM test/gotCharacters WHERE name.firstname <> 'Daenerys') 
treecy commented 7 years ago

@shi-yuan Thanks a lot! If I want to do something like:

select sum(gms), A
from (
    select max(gms) as gms, A, B
    from test
    group by A, B
)
group by A

Is there any way possible?

treecy commented 7 years ago

I resolved this one by Pipeline aggregations. @shi-yuan Thank you all the same 😀 Hope you can implement this feature.

dick318 commented 7 years ago

@treecy select sum(gms), A from ( select max(gms) as gms, A, B from test group by A, B ) group by A 你举的例子中,用Pipeline aggregations怎么写的 能提供下吗

JamesZhan107 commented 5 years ago

@treecy May I ask how to do this: select count(*) cnt from (select a0.name from worker a0) ttt