# Subquery on Elastic Search

**URL:** <https://discuss.elastic.co/t/subquery-on-elastic-search/135084>\
**Category:** Elasticsearch\
**Created:** [June 8, 2018, 5:35am UTC](https://discuss.elastic.co/t/subquery-on-elastic-search/135084 "2018-06-08T05:35:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ranavivek083](https://avatars.discourse-cdn.com/v4/letter/r/e5b9ba/32.png) [@ranavivek083](https://discuss.elastic.co/u/ranavivek083)\
**Post date:** [June 8, 2018, 5:35am UTC](https://discuss.elastic.co/t/subquery-on-elastic-search/135084/1 "2018-06-08T05:35:45Z")

</div>

Hi, all!  
I am new to ElasticSearch. I have been translating SQL queries to ElasticSearch queries. I encountered a SQL query that I'm not able to translate. The query is as follows.

```
SELECT subtable.f_date, ROUND(sum(subtable.var*subtable.num_games)/sum(subtable.num_games), 1) as points FROM (SELECT f_pl_id, f_date, sum(colX)*100/sum(colY) as var, count(f_g_id) as num_games FROM database WHERE f_date >= '2018-04-01' AND f_date <= '2018-04-10' GROUP BY f_pl_id, f_date) as subtable GROUP BY f_date;

```

Best regards

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2018, 5:35am UTC](https://discuss.elastic.co/t/subquery-on-elastic-search/135084/2 "2018-07-06T05:35:48Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
