<?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  for functions in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339423#M233093</link>
    <description>&lt;P&gt;There is one row per date. to compare the difference over months, I was to sum the amount of each month, then find percentage change of the total price each month.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying the date_trunc function, but it isnt working.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 24 Mar 2022 00:05:34 GMT</pubDate>
    <dc:creator>mystefied_</dc:creator>
    <dc:date>2022-03-24T00:05:34Z</dc:date>
    <item>
      <title>Hive query  for functions</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339147#M233061</link>
      <description>&lt;P&gt;I'm a newbie, I want to calculate month on month percentage change in price change in my table. Im using hive and using query:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select year(stock_date),month(stock_date),sum(stock_price) over (partition by year(stock_date),month(stock_date) ORDER BY month(stock_date)), PERCENT_RANK() OVER(ORDER BY month(stock_date) DESC) AS per from table4;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it's generating, It's showing July 2019 at the top and goes descending thru the numbers. how do I get the months in correct order and the percentage change with it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mystefied__0-1648012945794.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/33979i402BA59E4CF83C6E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mystefied__0-1648012945794.png" alt="mystefied__0-1648012945794.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;can anyone help me understand what am I doing wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 05:30:12 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339147#M233061</guid>
      <dc:creator>mystefied_</dc:creator>
      <dc:date>2022-03-23T05:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query  for functions</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339223#M233067</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/96741"&gt;@mystefied_&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you be able to describe in words what is the desired results of the query?&lt;/P&gt;&lt;P&gt;The query above doesn't make much sense to me but if you explain what you want to achieve I should be able to help you get the right query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;André&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 09:14:28 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339223#M233067</guid>
      <dc:creator>araujo</dc:creator>
      <dc:date>2022-03-23T09:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query  for functions</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339386#M233077</link>
      <description>Sure, I want to compare pricing across months by viewing percentage change across months.&lt;BR /&gt;</description>
      <pubDate>Wed, 23 Mar 2022 13:28:13 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339386#M233077</guid>
      <dc:creator>mystefied_</dc:creator>
      <dc:date>2022-03-23T13:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query  for functions</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339421#M233091</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/96741"&gt;@mystefied_&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What's the granularity of the data in the table? Do you have one row per day, multiple rows per day?&lt;/P&gt;&lt;P&gt;What's the "month price" that you need to consider? Average of the intra-month prices, max, min?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ANdré&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 23:56:06 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339421#M233091</guid>
      <dc:creator>araujo</dc:creator>
      <dc:date>2022-03-23T23:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query  for functions</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339423#M233093</link>
      <description>&lt;P&gt;There is one row per date. to compare the difference over months, I was to sum the amount of each month, then find percentage change of the total price each month.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying the date_trunc function, but it isnt working.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 00:05:34 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339423#M233093</guid>
      <dc:creator>mystefied_</dc:creator>
      <dc:date>2022-03-24T00:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query  for functions</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339549#M233105</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/96741"&gt;@mystefied_&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please try this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;select
  month,
  month_total,
  month_total / lag(month_total, 1) over (order by month) as percentage_over_previous_month,
  sum(month_total) over (order by month) as running_sum,
  sum(month_total) over (order by month) / sum(month_total) over (partition by 1) as running_percentage
from (
  select
    trunc(stock_date, 'MONTH') as month,
    sum(stock_price) as month_total
  from table4
  group by trunc(stock_date, 'MONTH')
) x&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;André&lt;/P&gt;&lt;P&gt;&lt;EM&gt;--&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Was your question answered? Please take some time to click on "&lt;STRONG&gt;Accept as Solution&lt;/STRONG&gt;" below this post.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;If you find a reply useful, say thanks by clicking on the thumbs up button.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 09:41:40 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339549#M233105</guid>
      <dc:creator>araujo</dc:creator>
      <dc:date>2022-03-24T09:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query  for functions</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339606#M233131</link>
      <description>&lt;P&gt;Im getting this error when executing the above query, I might be running an old version of hive&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FAILED: SemanticException [Error 10011]: Line 4:9 Invalid function 'trunc'&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 17:44:41 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339606#M233131</guid>
      <dc:creator>mystefied_</dc:creator>
      <dc:date>2022-03-24T17:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query  for functions</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339620#M233138</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/96741"&gt;@mystefied_&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which version of Hive are you using? That query works well on my cluster.&lt;/P&gt;&lt;P&gt;Nevertheless, you should be able to run the below, which is pretty much the same:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;select
  yr,
  mth,
  month_total,
  month_total / lag(month_total, 1) over (order by yr, mth) as percentage_over_previous_month,
  sum(month_total) over (order by yr, mth) as running_sum,
  sum(month_total) over (order by yr, mth) / sum(month_total) over (partition by 1) as running_percentage
from (
  select
    year(stock_date) as yr,
    month(stock_date) as mth,
    sum(stock_price) as month_total
  from table4
  group by year(stock_date), month(stock_date)
) x&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;André&lt;/P&gt;&lt;P&gt;&lt;EM&gt;--&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Was your question answered? Please take some time to click on "&lt;STRONG&gt;Accept as Solution&lt;/STRONG&gt;" below this post.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;If you find a reply useful, say thanks by clicking on the thumbs up button.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 22:50:15 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339620#M233138</guid>
      <dc:creator>araujo</dc:creator>
      <dc:date>2022-03-24T22:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query  for functions</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339769#M233168</link>
      <description>&lt;P&gt;I am running version&amp;nbsp;Hive 1.1.0-cdh5.4.3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I ran the most recent query, It's giving me the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mystefied__0-1648272163481.jpeg" style="width: 985px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/34037iE7F4FD07BE20D589/image-dimensions/985x250?v=v2" width="985" height="250" role="button" title="mystefied__0-1648272163481.jpeg" alt="mystefied__0-1648272163481.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2022 05:24:30 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339769#M233168</guid>
      <dc:creator>mystefied_</dc:creator>
      <dc:date>2022-03-26T05:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query  for functions</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339771#M233170</link>
      <description>&lt;P&gt;Woah! CDH 5.4.3 is *really* old. Unfortunatelly I don't have a cluster running that version here to test.&lt;/P&gt;&lt;P&gt;Hive has come a long way since then. We're already using Hive 3 on CDP 7.x.&lt;/P&gt;&lt;P&gt;I'd recommend you upgrade your system, if possible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;André&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2022 05:29:26 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339771#M233170</guid>
      <dc:creator>araujo</dc:creator>
      <dc:date>2022-03-26T05:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query  for functions</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339772#M233171</link>
      <description>&lt;P&gt;Im using a VM that is running this version. I'll try if I can update it. In case I can then I;ll try your queries again.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for trying to help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2022 05:38:51 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339772#M233171</guid>
      <dc:creator>mystefied_</dc:creator>
      <dc:date>2022-03-26T05:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query  for functions</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339779#M233175</link>
      <description>&lt;P&gt;Hello Andre,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you share the steps to upgrade the CDH / Hive to version 2 or 3 so at least the above commands can execute.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Also advise if I can download CDH 7 or 6 VM from Cloudera website, I do not have an active subscription but need trial for few days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for your help.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2022 15:04:06 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339779#M233175</guid>
      <dc:creator>mystefied_</dc:creator>
      <dc:date>2022-03-26T15:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: Hive query  for functions</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339792#M233183</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/96741"&gt;@mystefied_&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can download the CDP Trial version from the Cloudera website below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.cloudera.com/downloads/cdp-private-cloud-trial/cdp-private-cloud-base-trial.html" target="_blank"&gt;https://www.cloudera.com/downloads/cdp-private-cloud-trial/cdp-private-cloud-base-trial.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;André&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Mar 2022 22:42:38 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hive-query-for-functions/m-p/339792#M233183</guid>
      <dc:creator>araujo</dc:creator>
      <dc:date>2022-03-27T22:42:38Z</dc:date>
    </item>
  </channel>
</rss>

