# SQL - Perform ORDR BY SUM(col1\*col2)

**URL:** <https://discuss.elastic.co/t/sql-perform-ordr-by-sum-col1-col2/294300>\
**Category:** Kibana\
**Tags:** elastic-stack-sql\
**Created:** [January 13, 2022, 3:48pm UTC](https://discuss.elastic.co/t/sql-perform-ordr-by-sum-col1-col2/294300 "2022-01-13T15:48:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yamaga](https://avatars.discourse-cdn.com/v4/letter/y/858c86/32.png) [@yamaga](https://discuss.elastic.co/u/yamaga)\
**Post date:** [January 13, 2022, 3:48pm UTC](https://discuss.elastic.co/t/sql-perform-ordr-by-sum-col1-col2/294300/1 "2022-01-13T15:48:54Z")

</div>

Hi

I am willing to execute this query, retreive the top products with haghiest value:

`SELECT ID_PROD, SUM(PRICE*VOLUME) AS **VALUE** FROM sales group by ID_PROD ORDER BY VALUE`

I receive this error:

```auto
{
  "message": "Client request error: Parse Error",
  "statusCode": 502,
  "error": "Bad Gateway"
}

```

it works when I try this one:  
`SELECT ID_PROD, PRICE FROM sales ORDER BY PRICE`

How can I perform this kind of queries?

Thanks

---

<div class="post-metadata">

**Author:** ![Andrei\_Stefan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_stefan/32/47533_2.png) [@Andrei\_Stefan](https://discuss.elastic.co/u/Andrei_Stefan)\
**Post date:** [January 14, 2022, 12:44pm UTC](https://discuss.elastic.co/t/sql-perform-ordr-by-sum-col1-col2/294300/2 "2022-01-14T12:44:00Z")

</div>

@yamaga What ES version are you using? This is supported starting with ES 7.8.0.  
Also, the error you posted there is not ES SQL specific. "Bad Gateway" is a http error that probably comes from a intermediary system that sits between the client using the ES service and ES.

---

<div class="post-metadata">

**Author:** ![yamaga](https://avatars.discourse-cdn.com/v4/letter/y/858c86/32.png) [@yamaga](https://discuss.elastic.co/u/yamaga)\
**Post date:** [January 28, 2022, 3:29pm UTC](https://discuss.elastic.co/t/sql-perform-ordr-by-sum-col1-col2/294300/3 "2022-01-28T15:29:18Z")

</div>

It works when I added DESC after ORDER BY

`SELECT ID_PROD, SUM(PRICE*VOLUME) AS **VALUE** FROM sales group by ID_PROD ORDER BY VALUE **DESC** `

---

<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:** [February 25, 2022, 3:30pm UTC](https://discuss.elastic.co/t/sql-perform-ordr-by-sum-col1-col2/294300/4 "2022-02-25T15:30:04Z")

</div>

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