title: Hive query to read row and put it into table column
body: <p>I am creating hive table having sales records of different country date wise.</p>
  
  <pre><code>create external table sales_records (sales_date string, country string, sales bigint)
  --partitioned by (country string)
  -- sorted by (sales_date)
  row format delimited
  fields terminated by ','
  lines terminated by '\n'
  stored as textfile;
  </code></pre>
  
  <p>I inserted record in it.</p>
  
  <pre><code>insert into sales_records values 
      ("2018-01-01", "us", 5000) ,
      ("2018-01-02", "us", 500) ,
      ("2018-01-03", "us", 5500) ,
      ("2018-01-04", "us", 1500) ,
      ("2018-01-01", "ind", 500) ,
      ("2018-01-03", "ind", 500) ,
      ("2018-01-04", "ind", 5500) ,
      ("2018-01-06", "ind", 1500) ;
  </code></pre>
  
  <p>Now I need records in a way that output must contain:</p>
  
  <p>us_sales = sales in us at date</p>
  
  <p>ind_sales = sales in ind at date</p>
  
  <p>difference = | us_sales - ind_sales|</p>
  
  <pre><code>sales_date  | us_sales |  ind_sales  | difference
  --------------------------------------------------
  2018-01-01  |  5000    |   500       |  4500
  -------------------------------------------------
  2018-01-02  |  500     |     0       |   500
  -------------------------------------------------
  2018-01-03  |  5500    |   500       |  5000
  -------------------------------------------------
  2018-01-04  |  1500    |  5500       |  4000
  -------------------------------------------------
  2018-01-06  |     0    |  1500       |  1500
  -------------------------------------------------
  </code></pre>