<?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>topic Re: Why CTE is having issues with Databricks here? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/why-cte-is-having-issues-with-databricks-here/m-p/14014#M8579</link>
    <description>&lt;P&gt;Issue is coming because of the semicolon beside PhoneBrandSales. Try removing that ; issue will be resolved. Please refer to the screenshot below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please select this answer as best answer if it resolved your issue&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Varshith&lt;/P&gt;</description>
    <pubDate>Sun, 01 Jan 2023 09:54:27 GMT</pubDate>
    <dc:creator>Varshith</dc:creator>
    <dc:date>2023-01-01T09:54:27Z</dc:date>
    <item>
      <title>Why CTE is having issues with Databricks here?</title>
      <link>https://community.databricks.com/t5/data-engineering/why-cte-is-having-issues-with-databricks-here/m-p/14013#M8578</link>
      <description>&lt;P&gt;df = spark.createDataFrame([(2018,'Apple1',45000),(2019,'Apple1',35000),(2020,'Apple1',75000),&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(2018,'Samsung',15000),(2019,'Samsung',20000),(2020,'Samsung',25000),&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(2018,'Nokia',21000),(2019,'Nokia',17000),(2020,'Nokia',14000)],&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;['Year', 'Brand', 'Sales'])&lt;/P&gt;
&lt;P&gt;df.createOrReplaceTempView('PhoneBrandSales')&lt;/P&gt;
&lt;P&gt;spark.sql('SELECT * FROM PhoneBrandSales').show()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%sql&lt;/P&gt;
&lt;P&gt;SELECT *,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lead(Sales, 1, 0)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OVER(PARTITION BY Brand ORDER BY Year desc) AS PreviousYearSales&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FROM PhoneBrandSales;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%sql&lt;/P&gt;
&lt;P&gt;-- &lt;A href="https://www.sqlservertutorial.net/sql-server-window-functions/sql-server-lag-function/" target="test_blank"&gt;https://www.sqlservertutorial.net/sql-server-window-functions/sql-server-lag-function/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;WITH&lt;/STRONG&gt; CTE &lt;STRONG&gt;AS&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;(&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;SELECT&lt;/STRONG&gt; *,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Lead(Sales, 1, 0)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;OVER&lt;/STRONG&gt;(&lt;STRONG&gt;PARTITION&lt;/STRONG&gt; &lt;STRONG&gt;BY&lt;/STRONG&gt; Brand &lt;STRONG&gt;ORDER&lt;/STRONG&gt; &lt;STRONG&gt;BY&lt;/STRONG&gt; Year &lt;STRONG&gt;desc&lt;/STRONG&gt;) &lt;STRONG&gt;AS&lt;/STRONG&gt; PreviousYearSales&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;FROM&lt;/STRONG&gt; PhoneBrandSales;&lt;/P&gt;
&lt;P&gt;)&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SELECT&lt;/STRONG&gt; * &lt;STRONG&gt;FROM&lt;/STRONG&gt; CTE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ParseException:&lt;/P&gt;
&lt;P&gt;no viable alternative at input 'WITH CTE AS\n(\n SELECT *, \n Lead(Sales, 1, 0) \n OVER(PARTITION BY Brand ORDER BY Year desc) AS PreviousYearSales \n FROM PhoneBrandSales'(line 6, pos 22)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;== SQL ==&lt;/P&gt;
&lt;P&gt;WITH CTE AS&lt;/P&gt;
&lt;P&gt;(&lt;/P&gt;
&lt;P&gt;SELECT *,&lt;/P&gt;
&lt;P&gt;Lead(Sales, 1, 0)&lt;/P&gt;
&lt;P&gt;OVER(PARTITION BY Brand ORDER BY Year desc) AS PreviousYearSales&lt;/P&gt;
&lt;P&gt;FROM PhoneBrandSales&lt;/P&gt;
&lt;P&gt;----------------------^^^&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Mar 2025 13:27:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/why-cte-is-having-issues-with-databricks-here/m-p/14013#M8578</guid>
      <dc:creator>THIAM_HUATTAN</dc:creator>
      <dc:date>2025-03-21T13:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Why CTE is having issues with Databricks here?</title>
      <link>https://community.databricks.com/t5/data-engineering/why-cte-is-having-issues-with-databricks-here/m-p/14014#M8579</link>
      <description>&lt;P&gt;Issue is coming because of the semicolon beside PhoneBrandSales. Try removing that ; issue will be resolved. Please refer to the screenshot below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please select this answer as best answer if it resolved your issue&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Varshith&lt;/P&gt;</description>
      <pubDate>Sun, 01 Jan 2023 09:54:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/why-cte-is-having-issues-with-databricks-here/m-p/14014#M8579</guid>
      <dc:creator>Varshith</dc:creator>
      <dc:date>2023-01-01T09:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Why CTE is having issues with Databricks here?</title>
      <link>https://community.databricks.com/t5/data-engineering/why-cte-is-having-issues-with-databricks-here/m-p/14015#M8580</link>
      <description>&lt;P&gt;FANTASTIC, it is solved, thanks a lot for the prompt answer.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Jan 2023 11:57:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/why-cte-is-having-issues-with-databricks-here/m-p/14015#M8580</guid>
      <dc:creator>THIAM_HUATTAN</dc:creator>
      <dc:date>2023-01-01T11:57:31Z</dc:date>
    </item>
  </channel>
</rss>

