# Convert query from Mysql to curl

**URL:** <https://discuss.elastic.co/t/convert-query-from-mysql-to-curl/118643>\
**Category:** Elasticsearch\
**Created:** [February 6, 2018, 12:34pm UTC](https://discuss.elastic.co/t/convert-query-from-mysql-to-curl/118643 "2018-02-06T12:34:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![devil\_srj7](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@devil\_srj7](https://discuss.elastic.co/u/devil_srj7)\
**Post date:** [February 6, 2018, 12:34pm UTC](https://discuss.elastic.co/t/convert-query-from-mysql-to-curl/118643/1 "2018-02-06T12:34:13Z")

</div>

```
SELECT

	st.branch_id branch_id,

	st.branch_name branch_name,

	st.dept_id dept_id,

	st.dept_name dept_name,

	ROUND(SUM(IFNULL(st.work_allotment,0.0)/10000000)) work_allotment,

	ROUND(SUM(IFNULL(st.progMonth_Exp,0.0)/10000000)) progMonth_Exp,

	ROUND(SUM(IFNULL(st.month_Exp,0.0)/10000000)) month_Exp,

	ROUND(SUM(IFNULL(st.yearlyMonth_Exp,0.0)/10000000)) yearlyMonth_Exp,

	COUNT(DISTINCT st.division_office_id,st.work_id) total_works

FROM	
	mis_monthly_work_statistics st
  
       group by dept_id
;

```

I need to convert this query to curl.  
I am able to perform aggregation as follows:

```
{
  "aggs": {
    "By Dept": {
      "terms": {
        "field": "dept_id",
        "size": 10
      },
      "aggs": {
        "work_allotment": {
          "sum": {
            "field": "work_allotment"
          }
        },
        "progmonth_exp":{
          "sum": {
            "field": "progmonth_exp"
          }
        },
        "month_exp":{
          "sum": {
            "field": "month_exp"
          }
        },
        "yearlymonth_exp":{
          "sum": {
            "field": "yearlymonth_exp"
          }
        }
      }
    }
  }
}

```

But I alaso need to get the fields that are required.

---

<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:** [March 6, 2018, 12:34pm UTC](https://discuss.elastic.co/t/convert-query-from-mysql-to-curl/118643/2 "2018-03-06T12:34:30Z")

</div>

Closed on March 6, 2018, 12:34pm UTC

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