<?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: How to count the number of campaigns per day based on the start and end dates of the campaigns in SQL Spark Databrick in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-count-the-number-of-campaigns-per-day-based-on-the-start/m-p/18879#M12588</link>
    <description>&lt;P&gt;Just create an array with sequence, explode it, and then group and count:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;WITH cte AS
(SELECT
  `campaign name`, 
  explode(sequence(`Start date`, `End date`, interval 1 day)) as `Date`
FROM
  `campaigns`)
SELECT
  Count(`campaign name`) as `count unique campaigns`,
  `Date`
FROM
  cte
GROUP BY
  `Date`;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 03 Dec 2022 20:26:18 GMT</pubDate>
    <dc:creator>Hubert-Dudek</dc:creator>
    <dc:date>2022-12-03T20:26:18Z</dc:date>
    <item>
      <title>How to count the number of campaigns per day based on the start and end dates of the campaigns in SQL Spark Databrick</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-count-the-number-of-campaigns-per-day-based-on-the-start/m-p/18877#M12586</link>
      <description>&lt;P&gt;I need to count the number of campaigns per day based on the start and end dates of the campaigns&lt;/P&gt;&lt;P&gt;&lt;B&gt;Input Table:&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image 1"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1053iAFD5D27E81A52875/image-size/large?v=v2&amp;amp;px=999" role="button" title="image 1" alt="image 1" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Out needed&amp;nbsp;&lt;B&gt;(result):&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image 2"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1055iEE97E638ACB7C63F/image-size/large?v=v2&amp;amp;px=999" role="button" title="image 2" alt="image 2" /&gt;&lt;/span&gt;How do I need to write the&amp;nbsp;&lt;B&gt;SQL&lt;/B&gt;&amp;nbsp;command in databricks to get the above result? thanks all&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2022 09:01:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-count-the-number-of-campaigns-per-day-based-on-the-start/m-p/18877#M12586</guid>
      <dc:creator>dulu</dc:creator>
      <dc:date>2022-12-03T09:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of campaigns per day based on the start and end dates of the campaigns in SQL Spark Databrick</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-count-the-number-of-campaigns-per-day-based-on-the-start/m-p/18878#M12587</link>
      <description>&lt;P&gt;Hi @Du Lu​&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step1 : Collect all the dates between start date and end date as the campaign is happening on those dates. &lt;/P&gt;&lt;P&gt;Step2; Explode the collected date set&lt;/P&gt;&lt;P&gt;Step3: Count the number of campaigns happening on a particular date using a simple grouping expression.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Query looks something like this : (assuming startDate and EndDate are date columns and not strings. If strings, cast to date before proceeding).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select count(campaignName) as CampaignCount , EventDate from &lt;/P&gt;&lt;P&gt;( select campaignName, explode(sequence(StartDate, EndDate, interval 1 day)) as EventDate from source)&lt;/P&gt;&lt;P&gt;group by 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want specific date range you can do that by adding a where clause in the above query. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select count(campaignName) as CampaignCount , EventDate from &lt;/P&gt;&lt;P&gt;( select campaignName, explode(sequence(StartDate, EndDate, interval 1 day)) as EventDate from source)&lt;/P&gt;&lt;P&gt;where EventDate&amp;nbsp;between "2022-07-06" and "2022-08-03"&lt;/P&gt;&lt;P&gt;group by 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps...&lt;/P&gt;&lt;P&gt;Cheers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2022 10:11:02 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-count-the-number-of-campaigns-per-day-based-on-the-start/m-p/18878#M12587</guid>
      <dc:creator>UmaMahesh1</dc:creator>
      <dc:date>2022-12-03T10:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of campaigns per day based on the start and end dates of the campaigns in SQL Spark Databrick</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-count-the-number-of-campaigns-per-day-based-on-the-start/m-p/18879#M12588</link>
      <description>&lt;P&gt;Just create an array with sequence, explode it, and then group and count:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;WITH cte AS
(SELECT
  `campaign name`, 
  explode(sequence(`Start date`, `End date`, interval 1 day)) as `Date`
FROM
  `campaigns`)
SELECT
  Count(`campaign name`) as `count unique campaigns`,
  `Date`
FROM
  cte
GROUP BY
  `Date`;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2022 20:26:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-count-the-number-of-campaigns-per-day-based-on-the-start/m-p/18879#M12588</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2022-12-03T20:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of campaigns per day based on the start and end dates of the campaigns in SQL Spark Databrick</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-count-the-number-of-campaigns-per-day-based-on-the-start/m-p/18880#M12589</link>
      <description>&lt;P&gt;Nice query...&lt;/P&gt;</description>
      <pubDate>Sat, 10 Dec 2022 09:04:06 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-count-the-number-of-campaigns-per-day-based-on-the-start/m-p/18880#M12589</guid>
      <dc:creator>boyelana</dc:creator>
      <dc:date>2022-12-10T09:04:06Z</dc:date>
    </item>
  </channel>
</rss>

