# ElasticSQL math operation

**URL:** <https://discuss.elastic.co/t/elasticsql-math-operation/184680>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [June 7, 2019, 2:02am UTC](https://discuss.elastic.co/t/elasticsql-math-operation/184680 "2019-06-07T02:02:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Woolis\_Xiibil\_Peek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/woolis_xiibil_peek/32/42830_2.png) [@Woolis\_Xiibil\_Peek](https://discuss.elastic.co/u/Woolis_Xiibil_Peek)\
**Post date:** [June 7, 2019, 2:02am UTC](https://discuss.elastic.co/t/elasticsql-math-operation/184680/1 "2019-06-07T02:02:09Z")

</div>

Hi.

I need to substract two queries. I have try this

SELECT SUM ((SELECT COUNT (_) AS "op\_totals" FROM "app20-_" WHERE "path" = '/ops/login') - (SELECT COUNT (_) AS "op\_succ" FROM "app20-_" WHERE "operacion" = 79)) AS "op\_fail"

But I get an error that

Expression failed with the message:

[essql] \> Unexpected error from Elasticsearch: [unsupported\_operation\_exception] null

What I'm doing wrong? Please HELP!!!!  
:(😢

---

<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:** [June 7, 2019, 4:27pm UTC](https://discuss.elastic.co/t/elasticsql-math-operation/184680/2 "2019-06-07T16:27:13Z")

</div>

Hi @Woolis_Xiibil_Peek,

This type of operation is not supported. [Anything that involves sub-selects is in general unsupported](https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-limitations.html#_using_a_sub_select).

---

<div class="post-metadata">

**Author:** ![Woolis\_Xiibil\_Peek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/woolis_xiibil_peek/32/42830_2.png) [@Woolis\_Xiibil\_Peek](https://discuss.elastic.co/u/Woolis_Xiibil_Peek)\
**Post date:** [June 7, 2019, 5:15pm UTC](https://discuss.elastic.co/t/elasticsql-math-operation/184680/3 "2019-06-07T17:15:38Z")

</div>

Is there another way to do it?

---

<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:** [June 10, 2019, 12:08pm UTC](https://discuss.elastic.co/t/elasticsql-math-operation/184680/4 "2019-06-10T12:08:26Z")

</div>

What is your complete query?

---

<div class="post-metadata">

**Author:** ![Woolis\_Xiibil\_Peek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/woolis_xiibil_peek/32/42830_2.png) [@Woolis\_Xiibil\_Peek](https://discuss.elastic.co/u/Woolis_Xiibil_Peek)\
**Post date:** [June 11, 2019, 6:59pm UTC](https://discuss.elastic.co/t/elasticsql-math-operation/184680/5 "2019-06-11T18:59:31Z")

</div>

Hi Andrei.

I need to substract this two queries.

SELECT COUNT (_) AS "op\_totals" FROM "app20-_" WHERE "path" = '/ops/login'

and

SELECT COUNT (_) AS "op\_succ" FROM "app20-_" WHERE "operacion" = 79

Something like op\_totals - op\_succ

I also have try

SELECT COUNT("path") - COUNT("operacion") AS "x" FROM "app20-\*" WHERE "path" = '/ops/login' (something) "operacion" = 79

But I missing something between path and operación on WHERE sentence

---

<div class="post-metadata">

**Author:** ![tims](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tims/32/46750_2.png) [@tims](https://discuss.elastic.co/u/tims)\
**Post date:** [June 12, 2019, 7:09pm UTC](https://discuss.elastic.co/t/elasticsql-math-operation/184680/6 "2019-06-12T19:09:34Z")

</div>

Could you do something like  
SELECT COUNT(\*) as "total" FROM "app20-" WHERE "path" = '/ops/login' AND "operacion" != 79

Maybe I'm missing something.

---

<div class="post-metadata">

**Author:** ![Woolis\_Xiibil\_Peek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/woolis_xiibil_peek/32/42830_2.png) [@Woolis\_Xiibil\_Peek](https://discuss.elastic.co/u/Woolis_Xiibil_Peek)\
**Post date:** [June 19, 2019, 8:17pm UTC](https://discuss.elastic.co/t/elasticsql-math-operation/184680/7 "2019-06-19T20:17:41Z")

</div>

Hi.

Thank you, but it didn't make what I looking for.

I like to make the substraction of the total of the operations minus the succesful operations to get the failed operations.

ops\_failed = ops\_total - ops\_ succ.

I use this two queries to get the values

1. SELECT COUNT ( _) AS "op\_totals" FROM "app20-_ " WHERE "path" = '/ops/login'
2. SELECT COUNT ( _) AS "op\_succ" FROM "app20-_ " WHERE "operacion" = 79

But I'm failling making the math operation.

---

<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 17, 2019, 8:17pm UTC](https://discuss.elastic.co/t/elasticsql-math-operation/184680/8 "2019-07-17T20:17:43Z")

</div>

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