<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Hive query to check mathematical values from multiple tables in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-to-check-mathematical-values-from-multiple-tables/m-p/387775#M246423</link>
    <description>&lt;P&gt;Thanks! because i have null values in my data set as well, i used colaesce, and it worked! Your query was the basis though, so thanks again!&lt;BR /&gt;Query by &lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/61058"&gt;@nramanaiah&lt;/a&gt;&amp;nbsp;that worked for me, as I have null records in the dataset:&lt;/P&gt;&lt;P&gt;select Currency, (coalesce(spend_a,0)) + (colaesce(spend_b,0)) + coalesce(spend_c,0)) + coalesce(spend_d,0)) as total_spend from test&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 May 2024 18:01:18 GMT</pubDate>
    <dc:creator>Supernova</dc:creator>
    <dc:date>2024-05-10T18:01:18Z</dc:date>
    <item>
      <title>Hive query to check mathematical values from multiple tables</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-to-check-mathematical-values-from-multiple-tables/m-p/387063#M246236</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking to create a query to check and validate the math on certain fields from different tables. I've found examples where the SUM function was used- but I struggled putting it together, and am just trying to find the best way to do these calcuations.&lt;/P&gt;&lt;P&gt;Sample data:&lt;/P&gt;&lt;P&gt;Customer table:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;Customer ID&lt;/TD&gt;&lt;TD width="50%"&gt;Money Spent&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;0001&lt;/TD&gt;&lt;TD width="50%"&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0002&lt;/TD&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0003&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Sales table:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;Order ID&lt;/TD&gt;&lt;TD width="50%"&gt;Amount&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;5005&lt;/TD&gt;&lt;TD width="50%"&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5006&lt;/TD&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5007&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Check sales math work in progress query(the query doesn't seem to work, returns a "delta" column with a {null} result:&lt;/P&gt;&lt;P&gt;SELECT&lt;/P&gt;&lt;P&gt;CAST(SUM(Customer.Money Spent - Sales.Amount) AS INT) AS DELTA&lt;/P&gt;&lt;P&gt;The desired output that I'd like:&lt;/P&gt;&lt;P&gt;Check table&lt;/P&gt;&lt;TABLE border="1" width="99.72413793103448%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%" height="30px"&gt;&amp;nbsp;Rule Name&lt;/TD&gt;&lt;TD width="50%" height="30px"&gt;Delta&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="30px"&gt;Sales Check&lt;/TD&gt;&lt;TD width="50%" height="30px"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sales Check&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sales Check&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2026 06:32:08 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-to-check-mathematical-values-from-multiple-tables/m-p/387063#M246236</guid>
      <dc:creator>Supernova</dc:creator>
      <dc:date>2026-04-21T06:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query to check mathematical values from multiple tables</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-to-check-mathematical-values-from-multiple-tables/m-p/387204#M246261</link>
      <description>&lt;P&gt;If you want to join the tables, you should have primary-foreign key relation.&lt;/P&gt;&lt;P&gt;ie., sales table should have customer_id column or customer table should have order_id column to map rows between 2 tables. Otherwise this is not achievable.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 14:51:26 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-to-check-mathematical-values-from-multiple-tables/m-p/387204#M246261</guid>
      <dc:creator>nramanaiah</dc:creator>
      <dc:date>2024-04-25T14:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query to check mathematical values from multiple tables</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-to-check-mathematical-values-from-multiple-tables/m-p/387224#M246265</link>
      <description>&lt;P&gt;Understood- so okay, added Customer ID to Sales table;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Customer table:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;Customer ID&lt;/TD&gt;&lt;TD width="50%"&gt;Money Spent&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;0001&lt;/TD&gt;&lt;TD width="50%"&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0002&lt;/TD&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0003&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Sales table:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%"&gt;Customer ID&lt;/TD&gt;&lt;TD width="25%"&gt;Order ID&lt;/TD&gt;&lt;TD width="50%"&gt;Amount&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;0001&lt;/TD&gt;&lt;TD width="25%"&gt;5005&lt;/TD&gt;&lt;TD width="50%"&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;0002&lt;/TD&gt;&lt;TD width="25%"&gt;5006&lt;/TD&gt;&lt;TD width="50%"&gt;250&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;0003&lt;/TD&gt;&lt;TD width="25%"&gt;5007&lt;/TD&gt;&lt;TD width="50%"&gt;50&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Check sales math work in progress query(the query doesn't seem to work, returns a "delta" column with a {null} result:&lt;/P&gt;&lt;P&gt;SELECT&lt;/P&gt;&lt;P&gt;CAST(SUM(Customer.Money Spent - Sales.Amount) AS INT) AS DELTA&lt;/P&gt;&lt;P&gt;The desired output that I'd like:&lt;/P&gt;&lt;P&gt;Check table&lt;/P&gt;&lt;TABLE border="1" width="99.72413793103448%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%" height="30px"&gt;&amp;nbsp;Rule Name&lt;/TD&gt;&lt;TD width="50%" height="30px"&gt;Delta&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="30px"&gt;Sales Check&lt;/TD&gt;&lt;TD width="50%" height="30px"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sales Check&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sales Check&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 25 Apr 2024 17:24:39 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-to-check-mathematical-values-from-multiple-tables/m-p/387224#M246265</guid>
      <dc:creator>Supernova</dc:creator>
      <dc:date>2024-04-25T17:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query to check mathematical values from multiple tables</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-to-check-mathematical-values-from-multiple-tables/m-p/387281#M246290</link>
      <description>&lt;P&gt;I dint see the full query in your description. Are you aggregating (SUM) delta column based on customer_id ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did the following simple repro without aggregates &amp;amp; able to get the results as expected.&lt;/P&gt;&lt;PRE&gt;create external table Customer(customer_id string, money_spent bigint) stored as textfile;&lt;BR /&gt;insert into customer values("0001", 500), ("0002", 250), ("0003", 100);&lt;BR /&gt;&lt;BR /&gt;create external table sales(customer_id string, order_id string, amount bigint) stored as textfile;&lt;BR /&gt;insert into sales values("0001", "5005", 500), ("0002", "5006", 250), ("0003", "5007", 50);&lt;BR /&gt;&lt;BR /&gt;select "Sales Check" as rule, (a.money_spent - b.amount) as delta from customer a join sales b on a.customer_id = b.customer_id;&lt;BR /&gt;+--------------+--------+&lt;BR /&gt;| rule | delta |&lt;BR /&gt;+--------------+--------+&lt;BR /&gt;| Sales Check | 0 |&lt;BR /&gt;| Sales Check | 0 |&lt;BR /&gt;| Sales Check | 50 |&lt;BR /&gt;+--------------+--------+&lt;BR /&gt;3 rows selected (15.186 seconds)&lt;/PRE&gt;&lt;P&gt;Let me know if this helps.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 15:46:36 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-to-check-mathematical-values-from-multiple-tables/m-p/387281#M246290</guid>
      <dc:creator>nramanaiah</dc:creator>
      <dc:date>2024-04-26T15:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query to check mathematical values from multiple tables</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-to-check-mathematical-values-from-multiple-tables/m-p/387729#M246407</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/61058"&gt;@nramanaiah&lt;/a&gt;. I realized that I gave a bad example before. Apologies.&lt;/P&gt;&lt;P&gt;Table CustCurr:&lt;/P&gt;&lt;TABLE border="1" width="95.14350854180331%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;Currency&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="30px"&gt;Spend_A&lt;/TD&gt;&lt;TD width="8.333333333333334%"&gt;Spend_B&lt;/TD&gt;&lt;TD width="4.166666666666667%"&gt;Spend_C&lt;/TD&gt;&lt;TD width="4.166666666666667%"&gt;Spend_D&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;GBP&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="30px"&gt;50&lt;/TD&gt;&lt;TD width="8.333333333333334%"&gt;25&lt;/TD&gt;&lt;TD width="4.166666666666667%"&gt;(20)&lt;/TD&gt;&lt;TD width="4.166666666666667%"&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;JPY&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="30px"&gt;50&lt;/TD&gt;&lt;TD width="8.333333333333334%"&gt;25&lt;/TD&gt;&lt;TD width="4.166666666666667%"&gt;(20)&lt;/TD&gt;&lt;TD width="4.166666666666667%"&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="30px"&gt;AUD&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="30px"&gt;50&lt;/TD&gt;&lt;TD width="8.333333333333334%"&gt;25&lt;/TD&gt;&lt;TD width="4.166666666666667%"&gt;(20)&lt;/TD&gt;&lt;TD width="4.166666666666667%"&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;The Output that I'd like to get(as a check- can't create temp\tables as i only have read access) is:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;Currency&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;total_spend_check&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;A_and_C&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;B_C_D&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;GBP&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;80&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;30&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;JPY&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;80&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;30&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;AUD&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;80&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;30&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;The query that I'm trying is:&lt;/P&gt;&lt;P&gt;SELECT Currency, SUM(Spend_A + Spend_B, + Spend_C + Spend_D) AS total_spend_check&lt;/P&gt;&lt;P&gt;FROM&lt;/P&gt;&lt;P&gt;CustCurr&lt;/P&gt;&lt;P&gt;WHERE&lt;/P&gt;&lt;P&gt;DateofAction = '2024-05-01'&lt;/P&gt;&lt;P&gt;GROUP BY Currency&lt;/P&gt;&lt;P&gt;Here's the incorrect result that I get with above query:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;currency&lt;/TD&gt;&lt;TD width="50%"&gt;total_spend_check&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;GBP&lt;/TD&gt;&lt;TD width="50%"&gt;null&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;JPY&lt;/TD&gt;&lt;TD&gt;null&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;AUD&lt;/TD&gt;&lt;TD width="50%"&gt;null&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I've tried coalesce, cast(field as int) with no avail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2024 20:57:36 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-to-check-mathematical-values-from-multiple-tables/m-p/387729#M246407</guid>
      <dc:creator>Supernova</dc:creator>
      <dc:date>2024-05-09T20:57:36Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query to check mathematical values from multiple tables</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-to-check-mathematical-values-from-multiple-tables/m-p/387732#M246410</link>
      <description>&lt;P&gt;Hive can't understand (20) as negative value. You should explicitly mention -20 in column value.&lt;/P&gt;&lt;P&gt;ie.,&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;+----------------+---------------+---------------+---------------+---------------+
| test.currency  | test.spend_a  | test.spend_b  | test.spend_c  | test.spend_d  |
+----------------+---------------+---------------+---------------+---------------+
| GBP            | 50            | 25            | -20           | 5             |
| JPY            | 50            | 25            | -20           | 5             |
| AUD            | 50            | 25            | -20           | 5             |
+----------------+---------------+---------------+---------------+---------------+

select Currency, (spend_a + spend_b + spend_c + spend_d) as total_spend from test;
+-----------+--------------+
| currency  | total_spend  |
+-----------+--------------+
| GBP       | 60.0         |
| JPY       | 60.0         |
| AUD       | 60.0         |
+-----------+--------------+&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 09 May 2024 21:50:20 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-to-check-mathematical-values-from-multiple-tables/m-p/387732#M246410</guid>
      <dc:creator>nramanaiah</dc:creator>
      <dc:date>2024-05-09T21:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query to check mathematical values from multiple tables</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-to-check-mathematical-values-from-multiple-tables/m-p/387775#M246423</link>
      <description>&lt;P&gt;Thanks! because i have null values in my data set as well, i used colaesce, and it worked! Your query was the basis though, so thanks again!&lt;BR /&gt;Query by &lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/61058"&gt;@nramanaiah&lt;/a&gt;&amp;nbsp;that worked for me, as I have null records in the dataset:&lt;/P&gt;&lt;P&gt;select Currency, (coalesce(spend_a,0)) + (colaesce(spend_b,0)) + coalesce(spend_c,0)) + coalesce(spend_d,0)) as total_spend from test&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 18:01:18 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-to-check-mathematical-values-from-multiple-tables/m-p/387775#M246423</guid>
      <dc:creator>Supernova</dc:creator>
      <dc:date>2024-05-10T18:01:18Z</dc:date>
    </item>
  </channel>
</rss>

