Multiple select statement in hive
<p>toi am fairly new to hive.
I have a table called stats as shown below</p>

<pre><code>from_date  |  to_date   |   customer_name |  callcount
-------------------------------------------------------
2016_01_01 | 2016_01_02 |  ABC            | 25  
2016_01_02 | 2016_01_03 |  ABC            | 53  
2016_01_03 | 2016_01_04 |  ABC            | 44  
2016_01_04 | 2016_01_05 |  ABC            | 55
</code></pre>

<p>I want to build a hive query will accept:
a) current time range (from and to time)
b) previous time range (from and to time)
c) customer name</p>

<p>For e.g.: the inputs will be:
current time range can be from time(2016_01_03) and to time(2016_01_05)
current time range can be from time(2016_01_01) and to time(2016_01_02) 
customer name can be ABC</p>

<p>And the result i want to display is:
current_call_count(sum of call counts for current time range), previous_call_count(sum of call counts for previous time range)
and difference between current_call_count &amp; previous_call_count</p>

<p>like this:</p>

<pre><code>customer | current_call_count | previous_call_count | Diff
---------------------------------------------------------
ABC      | 99                 | 25                  | 74
</code></pre>

<p>The query which i built was:</p>

<pre><code>select * from 
(
select sum(callCount) as current_count from stats 
where customer_name='ABC' and from_date&gt;='2016-04-03' and to_date&lt;='2016-04-05'
UNION ALL
select sum(callCount) as current_count from stats 
where customer_name='ABC' and from_date&gt;='2016-04-01' and to_date&lt;='2016-04-02'
  ) FINAL
</code></pre>

<p>I am not able to get the calculation and also not able to display result as columns. Please help</p>