<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anshita Tiwari on Medium]]></title>
        <description><![CDATA[Stories by Anshita Tiwari on Medium]]></description>
        <link>https://medium.com/@circlesnspirals.blog?source=rss-e3bf2f490da0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kRF9YKu6RANJXJcfinAphQ.png</url>
            <title>Stories by Anshita Tiwari on Medium</title>
            <link>https://medium.com/@circlesnspirals.blog?source=rss-e3bf2f490da0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 02:15:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@circlesnspirals.blog/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Interview Question on Pivoting Data using SQL]]></title>
            <link>https://medium.com/@circlesnspirals.blog/interview-question-on-pivoting-data-using-sql-70429df93236?source=rss-e3bf2f490da0------2</link>
            <guid isPermaLink="false">https://medium.com/p/70429df93236</guid>
            <category><![CDATA[data-manipulation]]></category>
            <category><![CDATA[data-transformation]]></category>
            <category><![CDATA[pivoting]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Anshita Tiwari]]></dc:creator>
            <pubDate>Thu, 10 Oct 2024 20:25:40 GMT</pubDate>
            <atom:updated>2024-10-10T20:25:40.653Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EvLSuRr3cwYs8rTCEh6Iow.png" /></figure><p><strong>Occupations — Source : HackerRank (Medium Difficulty)</strong></p><p><a href="https://medium.com/p/5760f2d6b9e9/">Pivoting</a> is turning the rows to columns which I have discussed in my <a href="https://medium.com/p/5760f2d6b9e9/">previous blog</a>.</p><p><strong>Question :</strong></p><p>Pivot the Occupation column in <strong>OCCUPATIONS</strong> so that each Name is sorted alphabetically and displayed underneath its corresponding Occupation. The output column headers should be Doctor, Professor, Singer, and Actor, respectively.</p><p><strong>Note:</strong> Print <strong>NULL</strong> when there are no more names corresponding to an occupation.</p><p><strong>Input Format : </strong>The<strong> OCCUPATIONS </strong>table is described as follows :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*CIUFPKdP2F4eHfztTPdRkA.png" /></figure><p>Occupation will only contain one of the following values: <strong>Doctor</strong>, <strong>Professor</strong>, <strong>Singer</strong> or <strong>Actor</strong>.<br><strong>Sample Input</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*3yEs4ucrRGPr5u-dEMk7kg.png" /><figcaption>occupations</figcaption></figure><p><strong>Sample Output</strong></p><pre>Jenny    Ashley     Meera  Jane<br>Samantha Christeen  Priya  Julia<br>NULL     Ketty      NULL</pre><p>Let’s break the problem.<br><strong>First :</strong> We need to maintain alphabetical order of the names doing same occupation. We will use row number window function to achieve this.<br>The PARTITION BY occupation will ensure that row numbering restarts for each occupation and ORDER BY name will sort the names alphabetically</p><pre>SELECT  name, occupation, <br>        ROW_NUMBER() OVER (PARTITION BY occupation ORDER BY name) as rnum<br>FROM   occupations</pre><p>Output :</p><pre>Name          Occupation    rnum<br>   <br>Eve           Actor         1<br>Jennifer      Actor         2<br>Ketty         Actor         3<br>Samantha      Actor         4<br>Aamina        Doctor        1    <br>Julia         Doctor        2<br>Priya         Doctor        3<br>Ashley        Professor     1<br>Belvet        Professor     2<br>Britney       Professor     3<br>Maria         Professor     4<br>Meera         Professor     5<br>Naomi         Professor     6<br>Priyanka      Professor     7<br>Christeen     Singer        1<br>Jane          Singer        2<br>Jenny         Singer        3<br>Kristeen      Singer        4</pre><p><strong>To use PIVOT we need to aggregate data on a common column (In this case row_number would do that job)</strong></p><p><strong>Second :</strong> As discussed in my previous blog, we will now <a href="https://medium.com/p/5760f2d6b9e9">pivot</a> the data.We will make a CTE of the above sql query and use the result to make pivot.</p><pre>with cte as <br>(<br>  SELECT  name, occupation, <br>        ROW_NUMBER() OVER (PARTITION BY occupation ORDER BY name) as rnum<br>  FROM   occupations<br>)<br>, cte1 as<br>(<br>  SELECT * <br>    FROM cte<br>    PIVOT (<br>        MAX(name)       -- aggregating on max() [can even use min()]<br>        FOR occupation <br>        IN  (&#39;Doctor&#39; AS doctor, <br>            &#39;Professor&#39; AS professor, <br>            &#39;Singer&#39; AS singer, <br>            &#39;Actor&#39; AS actor<br>            )<br>          )<br>)</pre><p><strong>Third :</strong> Final selection : The final selection retrieves the pivoted columns (doctor , professor , singer , and actor) sorted by their row_number</p><pre>select doctor,professor,singer,actor<br>from cte1<br>order by rnum;</pre><p>Combining everything :</p><pre>with cte as <br>(<br>  SELECT  name, occupation, <br>        ROW_NUMBER() OVER (PARTITION BY occupation ORDER BY name) as rnum<br>  FROM   occupations<br>)<br>, cte1 as<br>(<br>  SELECT * <br>    FROM cte<br>    PIVOT (<br>        MAX(name)       -- aggregating on max() [can even use min()]<br>        FOR occupation <br>        IN  (&#39;Doctor&#39; AS doctor, <br>            &#39;Professor&#39; AS professor, <br>            &#39;Singer&#39; AS singer, <br>            &#39;Actor&#39; AS actor<br>            )<br>          )<br>)<br>select doctor,professor,singer,actor<br>from cte1<br>order by rnum;</pre><p>OUTPUT :</p><pre>doctor   professor singer      actor<br><br>Aamina   Ashley    Christeen   Eve<br>Julia    Belvet    Jane        Jennifer<br>Priya    Britney   Jenny       Ketty<br>NULL     Maria     Kristeen    Samantha<br>NULL     Meera     NULL        NULL<br>NULL     Naomi     NULL        NULL<br>NULL     Priyanka  NULL        NULL</pre><p>If you learnt something from this article 😊- please give me a clap 👏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70429df93236" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PIVOTING IN SQL]]></title>
            <link>https://medium.com/@circlesnspirals.blog/pivoting-in-sql-5760f2d6b9e9?source=rss-e3bf2f490da0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5760f2d6b9e9</guid>
            <category><![CDATA[pivoting]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[data-transformation]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[oracle]]></category>
            <dc:creator><![CDATA[Anshita Tiwari]]></dc:creator>
            <pubDate>Thu, 10 Oct 2024 20:17:01 GMT</pubDate>
            <atom:updated>2024-10-10T20:22:36.941Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f5VHJsoMplanZUbQLPR0dQ.png" /></figure><p><strong>WHAT IS PIVOTING ?</strong> <br>Imagine you have a spreadsheet with data organized in rows and columns. Sometimes, you need to <strong>turn the rows into columns</strong> to make the information easier to understand. That’s exactly what pivoting does — it reorganizes data in a way that lets you quickly <strong>compare different categories side by side.</strong></p><p>In SQL, a <strong>pivot</strong> transforms rows of data into columns, helping you see patterns and trends more clearly. It’s like turning a list of payments into a <strong>summary table</strong> where each payment method becomes its own column. This makes it much easier to analyze the data.</p><h3>Why Pivoting is Useful?</h3><p>In organizations, analyzing <strong>data efficiently is key to making informed decisions</strong>. Here’s why pivoting is a game-changer:</p><ol><li><strong>Quick Comparison</strong>: By turning rows into columns, pivoting makes it easy to compare different categories (like payment methods) side by side.</li><li><strong>Better Decision-Making</strong>: In our example, you can quickly see which payment methods are growing in popularity. If PayPal usage is increasing, you might decide to offer special deals or optimize your checkout process for PayPal users.</li><li><strong>Clear Insights</strong>: Pivoting helps create <strong>clean, easy-to-read reports</strong>. Instead of sifting through messy data, you get a clear overview of important trends in your business.</li></ol><h3>Let’s Look at a Real-World Example</h3><p>Let’s say you have this data for customer orders from an e-commerce company, showing the <strong>number of orders by payment method</strong> for each month:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*OH3XR1IYluZeh0XkzqN0Pg.png" /><figcaption>orders_data ( Snippet for raw data)</figcaption></figure><p>This table gives you a lot of information, but it’s not the easiest to read or compare. What if you wanted to quickly see <strong>which payment method is the most popular each month</strong>? That’s where pivoting comes in handy.</p><h4>Pivoting the Data for Better Insights</h4><p>When you <strong>pivot</strong> the data, you turn the <strong>Payment Method</strong> values (like Credit Card, PayPal, Cash on Delivery) into columns, and the number of orders becomes easier to compare month by month.</p><p>After pivoting, your data would look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*XE0-x6EciG3ydxONMK2h6A.png" /><figcaption>orders_data ( Snippet of transformed data)</figcaption></figure><p>Now, instead of hunting through rows, you can <strong>instantly compare</strong> the number of orders made through different payment methods for each month. You can see at a glance that <strong>Credit Card</strong> is the most popular payment method in every month, while <strong>Cash on Delivery</strong> has the least number of orders.</p><h3>Syntax for Pivot</h3><pre>SELECT &lt;column_you_want_to_keep&gt; , &lt;pivoted_columns&gt;<br>FROM &lt;your_table_name&gt;<br>PIVOT<br>(<br>  &lt;aggregation_fucntion&gt; (&lt;column_to_be_aggreagated&gt;)<br>  FOR &lt;column_to_pivot&gt;<br>  IN (&lt;list_of_values_to_pivot_as_columns&gt;)<br>)AS &lt;pivot_table_alias&gt;<br>;</pre><blockquote>Explanation of Each Part:<br>1. &lt;columns_you_want_to_keep&gt;: These are the columns that won’t be changed, you keep them as they are(like <strong>Month </strong>in the e-commerce example)<br>2. &lt;pivoted_columns&gt;<strong>:</strong> These are the new column names that appear after pivoting (like ‘Credit Card’, ‘PayPal’, ‘Cash on Delivery’)<br>3. &lt;your_table_name&gt;: This is the name of the table that holds your data(e.g. ‘orders_data’).<br>4. &lt;aggregation_function&gt;: This is a function used to combine the data. It’s usually ‘SUM()’ / ‘COUNT()’ / ‘MAX()’ / ‘MIN()’ etc.<br>5. &lt;column_to_aggregate&gt;: This is the column you are summarizing. <br>6. &lt;column_to_pivot&gt;: This the column whose values you want to turn into new columns (like ‘Payment_Method’).<br>7. &lt;list_of_values_to_pivot_as_columns&gt;: This is a list of the va;ues in the column that will become the new column names (like ‘Credit Card’ , ‘PayPal’ , ‘Cash on Delivery’)<br>8. &lt;pivot_table_alias&gt;: This is just a name you give to the new pivoted table (you can call it anything, like ‘pivot_table’)</blockquote><h3>How to Use Pivot in SQL?</h3><p>Even if you’re not a techie, the idea behind writing a pivot query in SQL is straightforward. Think of it like telling the system:</p><ul><li><strong>“Look at this column”</strong> (in our case, the payment methods).</li><li><strong>“Turn the values into separate columns”</strong> (Credit Card, PayPal, Cash on Delivery).</li><li><strong>“Sum up / perform aggregation on the number of orders for each method”</strong> (how many orders were made using each method every month).</li></ul><p>Here’s a simplified version of what the SQL query might look like:</p><pre>SELECT Month, [Credit Card], PayPal, [Cash on Delivery]<br>FROM orders_data<br>PIVOT (<br>    SUM(Total_Orders) <br>    FOR Payment_Method IN (&#39;Credit Card&#39;, &#39;PayPal&#39;, &#39;Cash on Delivery&#39;)<br>) AS pivot_table;</pre><h3>How Can This Impact Your Business</h3><p>Let’s say you run a promotion in March offering a discount for customers who pay with <strong>Credit Card</strong>. After pivoting the data, you notice that Credit Card orders have jumped significantly in March compared to previous months:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*XE0-x6EciG3ydxONMK2h6A.png" /><figcaption>pivot_table</figcaption></figure><p>The pivot table shows that your promotion worked — <strong>Credit card </strong>payments doubled in March! This insight helps you make decisions on future marketing strategies and promotion.</p><p>I have also discussed a <a href="https://medium.com/p/70429df93236">real interview question</a> in my next blog.</p><p>If you learnt something from this article 😊- please give me a clap 👏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5760f2d6b9e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Netflix — Reinventing The Internet Market]]></title>
            <link>https://medium.com/@circlesnspirals.blog/netflix-reinventing-the-internet-market-2b8a6e47cdaa?source=rss-e3bf2f490da0------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b8a6e47cdaa</guid>
            <category><![CDATA[product-analysis]]></category>
            <category><![CDATA[digital-transformation]]></category>
            <category><![CDATA[marketing-strategies]]></category>
            <category><![CDATA[netflix]]></category>
            <category><![CDATA[strategy]]></category>
            <dc:creator><![CDATA[Anshita Tiwari]]></dc:creator>
            <pubDate>Thu, 24 Aug 2023 19:47:25 GMT</pubDate>
            <atom:updated>2023-08-24T19:47:25.341Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jhxfxe61P8V8Cz9-Dn_z0Q.png" /></figure><h3>Netflix — Reinventing The Internet Market</h3><p>This case study describes how a mere idea can make the biggest successful firms. We will analyze what are the reasons of its success. We will demonstrate how the revolution of streaming has brought content to a different place. Netflix is a business, we never really thought would sustain itself over so many pivots, but it has impressively re-invented itself multiple times.</p><p><strong>THE RISE OF NETFLIX</strong></p><p>Despite being an unequivocal powerhouse in a modern media consuming market, Netflix came from humble beginnings. Reed Hastings and Marc Randolph co-founded Netflix in Aug 1997. While carpooling together they discussed their own idea of shipping items over the emerging internet. They thought that VHS (Video Home Tapes) tapes were too fragile and expensive. So they set onto DVDs, which were brand new at that time. After a small test run of sending DVDs to themselves, they decided to go for the idea and in that moment, Netflix was born, and the company grew quickly.</p><p><strong>BLOCKBUSTER TURNING DOWN CHANCE TO BUY NETFLIX</strong></p><p>Interestingly Netflix approached Blockbuster in 2000 with a 50 million dollar offer, thinking it was a joke, Blockbuster laughed them straight out of the office. Undeterred Netflix continued to grow. Later in 2004, Blockbuster realized their mistake and soon launched their own DVD rental service. Unfortunately for Blockbuster bas management and excessive company debt led to its demise.</p><p><strong>A ROADMAP TO NETFLIX’s SUCCESS</strong></p><p>In my opinion, Netflix was successful due to <em>founding circumstances and the early adoption of DVDs</em>. They had the time, money and experience to think and come up with an idea and make it happen. I would argue that the obscurity of DVDs is the biggest reason that they made it through in the first couple of years. When the service first launched, they offered 7-day DVD rental for the price of $4 with $2 shipping in addition to selling new DVDs. For their first year, they brought in more money from selling rather than renting. DVDs being new and hard to find, made customers buy them as there were no more options available at that time. This leads to the next reason of moving their focus to rentals. In March 1999, they made a bold move to stop selling DVDs, cutting off the main source of revenue. For that year, the sales revenue accounted for only 3% for the first couple of months and by 2000, it was 0%. Netflix may have realized that insufficient competition was leading to greater sales, and it wouldn’t sustain when the competition starts catching up. In my opinion, if DVDs were infact the next best thing of that time, we must admit that soon it will also be sold in the stores across the country and that could have been a major threat to Netflix. This leads to the next reason of “<em>switching to subscription</em>” model. The rentals in 1999 consisted of 4 DVD rentals at $15.95/ month including shipping costs, which was later optimized to unlimited rental at $19.95/month with maximum of 4 DVD limit at a time. There was always a long-term strategy involved. For the first five years, Netflix didn’t make any profits. Moreover, they lost over a $150 million dollars. They received money from venture capitalists and in 2000 they raised $80 million dollars through a public stock offering. The <em>marketing strategy</em> was one of the biggest pillars of it being successful. They offered free trial services to attract new customers. They also partnered with different companies to give free Netflix subscription for customers buying new DVDs. The next major reason was the variety of selections and recommendations to customers on the genre of movies, personalized to individual preferences. In the year 2000, they started revenue sharing agreements with the studios for buying a high volume of DVDs at discounted price, reducing the risk of investment. In 2004, they announced their partnership with TiVo and worked together in an effective way to stream movies over the internet to people’s homes. It took some time and the first Netflix streaming happened in 2007 through their watch-now service. It was provided as a bonus service to the customers who were subscribed to their DVD service which clearly shows their customer obsession. From 2007–2010 Netflix built a powerful platform for every need. After that, since 2011 it extended its business and acquired more new customers. In February 2013, “House of cards” made its online debut which was a blockbuster.” Orange is the new black” was also aired in July of the same year. Since then, they launched several series that received positive critics: Marco Polo (2014), Daredevil (2015), Narcos (2015).</p><p>Netflix chose the right revenue model, the “<em>subscription revenue model</em>”. Subscription fee is charged from the user for the content they wish to access. Also, Netflix changes its library often for two reasons:</p><p>First, it diminishes the cost of licensing — if Netflix wishes to keep its content forever, the company will have to pay enormous amount of money to content producers.</p><p>Secondly, by refreshing the contents of their library, viewers are eager to come to the website for new added movies/TV shows.</p><p><strong>PORTER’s FIVE FORCE ANALYSIS</strong></p><p>Supplier Power: The bargaining power of supplier focusses on the ability of suppliers to raise prices, reduce product quality and availability. For instance, Netflix supplier powers are high because suppliers make movies and Netflix demands large volumes of movies and TV series. To reduce the supplier’s power Netflix is using backward integration. Example: Its own TV series-The house of cards.</p><p>Buyer Power: Netflix is the king of streaming videos and to continue to mitigate the threat of buyer power, Netflix should innovate on dressing these major issues-switching cost, video preferences, viewer preferences, movie and Tv show selection and refining the brand.</p><p>Threat of substitute: A substitute product is a product from another industry that offers similar benefits to the consumer as the product produced by the firm. Considering a high threat level for Netflix, the cost level and product diversities are the key leading factors that separate it from other streaming providers.</p><p>Competitive Rivalry: The competitive rivalry for Netflix is high. Some competitors are Amazon Prime, Hulu and several other networks. Additionally, the switching costs are low, making it easier for any subscriber to switch.</p><p>Threat of new entrants: The barriers of investment will be high if there are strict regulations or a need of special knowledge or high investment acquirements. For smaller companies the threat level is low because Netflix is offering a high economies of scale with high product variety with low cost and increasing profit. However bigger firms like Apple and Google which have high capital and technology can be a new threat.</p><p><strong>CONCLUSION:</strong></p><p>Netflix is the perfect example of a company that uses the Internet to reinvent the market. Netflix should be focusing more on user growth rather than streaming revenue growth. Netflix should invest in top-quality original content that will attract more users. Additionally, Netflix should target the global market to increase its subscription membership. Boosting the number of original contents will enable the company to diversify its target market. Netflix should also invest in other domains as it can attract young crowd to invest. For example: Gaming. They must also test to find the optimal balance between price and value with paid account sharing options in friends and family monthly subscription pack.</p><p><strong>References</strong>:</p><p><a href="https://www.linkedin.com/pulse/how-should-netflixs-product-strategy-change-given-its-mak-/?trk=pulse-article">https://www.linkedin.com/pulse/how-should-netflixs-product-strategy-change-given-its-mak-/?trk=pulse-article</a></p><p><a href="https://www.forbes.com/sites/danafeldman/2022/06/29/rather-than-quantity-netflix-should-focus-on-quality-like-hulu/?sh=4dfede032de4">https://www.forbes.com/sites/danafeldman/2022/06/29/rather-than-quantity-netflix-should-focus-on-quality-like-hulu/?sh=4dfede032de4</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b8a6e47cdaa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tetra Pak: A persistent desire to digitize their supply chain]]></title>
            <link>https://medium.com/@circlesnspirals.blog/tetra-pak-a-persistent-desire-to-digitize-their-supply-chain-d41e45368b44?source=rss-e3bf2f490da0------2</link>
            <guid isPermaLink="false">https://medium.com/p/d41e45368b44</guid>
            <category><![CDATA[supply-chain]]></category>
            <category><![CDATA[case-study]]></category>
            <category><![CDATA[tetra-pak]]></category>
            <category><![CDATA[swot-analysis]]></category>
            <category><![CDATA[digitization]]></category>
            <dc:creator><![CDATA[Anshita Tiwari]]></dc:creator>
            <pubDate>Thu, 24 Aug 2023 19:38:08 GMT</pubDate>
            <atom:updated>2023-08-24T19:38:08.093Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*CCB5uNaNSRG9ohXrfUyIDw.png" /><figcaption>TETRA PAK</figcaption></figure><p>Tetra Pak has made numerous strategic changes to its business model over the past years to address changing market conditions and therefore maintain its ability to add value. This case study describes how a mere idea of making sausages helped Tetra Pak become a world leader. With persistent innovation and digitization, it attained its place in the world of packaging. The technology landscape has been extremely dynamic over this period and companies that have not adapted rapidly have faced extinction. Moreover, the article also highlights some of the challenges Tetra Pak faced, how they expanded their capabilities and what their future roadmap looks like.</p><p><strong>A GLOBAL PIONEER IN PACKAGING TECHNOLOGY</strong></p><p>Since the beginning Tetra Pak was committed to excellence and innovation. Within the early 1990s, they came up with a Total Predictive Maintenance (TPM) — a program of a program of relentless, data driven reduction and elimination of productivity.<em> Exhibit 1</em> shows the innovative first packaging by Dr. Rausing — Tetra Pak — an oxygen free, aseptic, stackable, and easy to use package which replaced glass packaging that had issues of stack ability and was breakable. By 2017, the firm was able to come up with twelve different kinds of packaging. In later years, <em>The Total Productive Maintenance program</em> by the firm specifically aimed at enhancing performance and reducing losses using digital insights. This program was extremely successful that its continuous implementation gave Tetra Pak its first “<em>Japan Institute of plant Maintenance Global Leaders Award”</em>.</p><p>Tetra Pak’s vision has always been focused on making packages save more than it costs.</p><p><strong>A STRATEGIC APPROACH OF DIGITIZATION</strong></p><p>Tetra Pak after identifying its strategy of digitization established three key business priorities across its operations namely</p><p>· Improving the quality and performance</p><p>· Offer outcome-based service contracts</p><p>· Re-inventing the package</p><p>Under the leadership of Erik Winberg, the objective was to provide leadership in all digital supply chain management. The problem Eric faced was to convince the company’s leadership to develop the digital program office outside the company’s existing IT organization. It was indeed the tough decision as the company heavily was based on SAP. The leadership irrespective of their trivial approach, agreed Eric’s proposition. Digital technologies helped Tetra Pak get access to more sophisticated automation, higher resolution data, and greater depth of insight/analytics into quality and efficiency losses while maintain its core business strategy of saving costs and providing value. Data centers were created to provide a centralized capability for identifying and securing the sources of all data needed for selection of the projects. This concept aimed to overcome the limitations of SAP. Since the technology was new for many functional teams , Eric suggested that data science CoE should always be the starting point. They were able to achieve this milestone by <em>Connected Workforce</em> and <em>Advanced Analytics</em>. Along with the above-mentioned efforts, the firm invested internally on sensors to monitor every step in the manufacture of its packaging materials to fully capture all the potential areas of production disruption and areas of quality improvement. <em>However, the amount of data staggered and then the firm had to invest in automation of all movements via RFID sensors and Automated Guided Vehicles. </em>Using this sensor technology the amount of data that they were collecting was staggering and over 20000 different pieces of equipment were connected and compiled data through a cloud platform. Not restricting itself, Tetra Pak would then use advanced analytics and machine learning algorithms to identify problems in folds on customer filling lines. Tetra Pak was able to identify the quality incidents and product recalls to meet ever more stringent requirements by having a connected package which enables its customers more granularity in product traceability.</p><p><strong>SWOT Analysis</strong></p><p><strong>Strength:</strong></p><p>Being a market leader in full-fat, skimmed and semi-skimmed milk it had extensive distribution throughout the nation. Due to investments in technology and digitizing its product, it diversified its product portfolio. Additionally, it had strong relationship with leading packaging industry in the market. Tetra Pak has first mover advantage in number of segments. It has experimented in various areas Customers, Market research, Supply chain. The Sales &amp; Marketing solutions &amp; strategies have helped Tetra Pak in coming up with unique solution to tap the un-catered markets.</p><p><strong>Weakness:</strong></p><p>Tetra Pak’s business model can be easily replicated even with the number of patents and copyrights the company possess. The intellectual property rights are very difficult to implement in the industry that Tetra Pak operates in. Also, Tetra Pak is not diverse enough given that most of its growth so far is in its domestic market which can easily reduce its potential of success in the international market. Even though Tetra Pak has integrated technology in the backend processes it has still not able to harness the power of technology in the front-end processes. Although the demand for products have not gone down but there is a simmering sense of dissatisfaction among the customers of Tetra Pak. It should focus on areas where it can improve the customer purchase and post purchase experience.</p><p><strong>Opportunities</strong></p><p>Tetra Pak can use developments in artificial intelligence to better predict consumer demand, cater to niche segments, and make better recommendation engines. E-commerce business model can help Tetra Pak to tie up with local suppliers and logistics provider in international market. Social media growth can help Tetra Pak to reduce the cost of entering new market and reaching to customers at a significantly lower marketing budget. It can also lead to crowd sourcing various services and consumer-oriented marketing based on the data and purchase behavior. Tetra Pak can leverage its increasing standardization trend to reduce the number of offerings in the market and focus on the marketing efforts on only the most successful products.</p><p><strong>Threats</strong></p><p>Tetra Pak has focused on China for its next phase of growth. But there is growing tension between US China trade relations, and it can lead to protectionism, more friction into international trade, rising costs both in terms of labor cost and cost of doing business. As Tetra Pak can leverage low cost of reaching customers using social media and e-commerce, so can the competitors — both local and international competitors. The growing inequality is one of the biggest threats to not only globalization but also to capitalism. Tetra Pak first hand witnessed the impact of it where it has seen lower demand of its products from middle class customers in US and EU market.</p><p><strong>CONCLUSION</strong></p><p>Tetra Pak, should be more efficient and more sustainable in food packaging and should replace aluminum in its aseptic cartons with materials that reduce carbon footprint and improve recyclability, all without jeopardizing food safety. It should invest more in the development of packages made with a simplified material structure and increased renewable content. I believe in the Tetra Pak threat of new entrants is very low as it has advanced so much in its business and had invested heavily in research and development that its unmatchable for the new entrants.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d41e45368b44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rolling Averages in SQL]]></title>
            <link>https://medium.com/@circlesnspirals.blog/rolling-averages-in-sql-dd2d968c24d2?source=rss-e3bf2f490da0------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd2d968c24d2</guid>
            <category><![CDATA[sql-window-functions]]></category>
            <category><![CDATA[amazon-interview-question]]></category>
            <category><![CDATA[rolling-average]]></category>
            <category><![CDATA[revenue-over-time]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Anshita Tiwari]]></dc:creator>
            <pubDate>Mon, 21 Aug 2023 22:40:52 GMT</pubDate>
            <atom:updated>2023-08-21T23:52:12.234Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*hliRTdCXknV_21hMdtqbxg.png" /></figure><h4>What is rolling average?</h4><p>ARolling Average, also known as a moving average, is a statistical calculation used to analyze data over a sequence of consecutive periods. (For e.g. — calculate a rolling average of 3 months stock price based on two previous month’s and one current month’s stock price)</p><h4>Why do we use rolling averages?</h4><blockquote>1. <strong>Smoothing Data</strong> : Rolling averages help to reduce the impact of random fluctuations or noise in a dataset. By calculating an average over a specific window of time, the resulting value provides a smoother representation of the underlying trends.</blockquote><blockquote>2. <strong>Trend Identification : </strong>Rolling averages help to identify trends in data over time. By smoothing out short-term fluctuations, it becomes easier to discern long-term patterns and changes in the data. This is particularly useful in financial markets, where it’s often applied to stock prices or economic indicators.</blockquote><blockquote>3. <strong>Seasonal Patterns :</strong> In time-series data, there might be seasonal variations that occur on a regular interval, such as daily, weekly, bi-weekly. Rolling averages can help highlight these patterns by averaging data points over a period, making it easier to observe recurring trends.</blockquote><blockquote>4. <strong>Identification of Anomalies : </strong>Sudden spikes or drops in data can sometimes be hard to identify in raw data due to spikes. By using the same window size, you can compare the trends and variations between various entities or datasets.</blockquote><h4>How can we calculate it using ROWS clause: Syntax</h4><p>The purpose of the ROWS clause is <strong>to specify the window frame in relation to the current row</strong>. The syntax is:</p><p>ROWS BETWEEN <em>lower_bound</em> AND <em>upper_bound</em></p><p><strong>The bounds can be any of these five options:</strong></p><p>UNBOUNDED PRECEDING – All rows before the current row.</p><p>n PRECEDING – <em>n</em> rows <strong>before</strong> the current row.</p><p>CURRENT ROW – Just the current row.</p><p>n FOLLOWING – <em>n</em> rows <strong>after</strong> the current row.</p><p>UNBOUNDED FOLLOWING – All rows after the current row.</p><p>For instance : To understand the basic syntax of ROWS clause, we’ll use the following table with sales data from an e-commerce website. In this example we would like to add another column moving_average from the first day to the current day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*lyIhw3uNPYTnbMrQNx9F0w.png" /><figcaption>sales_cd</figcaption></figure><pre>SELECT date, revenue,<br>    SUM(revenue) OVER (<br>      ORDER BY date<br>      ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) moving_average<br>FROM sales_cd<br>ORDER BY date;</pre><h4>Understanding the concept using a real world interview problem</h4><blockquote>Let’s try to solve a questions using rolling average concept in sql.<br><strong>Company : Amazon</strong><br><strong>Difficulty level : Hard</strong></blockquote><h4>QUESTION : Revenue Over Time</h4><p>Find the 3-month rolling average of total revenue from purchases given a table with users, their purchase amount, and date purchased (YYYY-MM-DD). Do not include returns which are represented by negative purchase values. Output the year-month (YYYY-MM) and 3-month rolling average of revenue, sorted from earliest month to latest month.</p><p>A 3-month rolling average is defined by calculating the average total revenue from all user purchases for the current month and previous two months. The first two months will not be a true 3-month rolling average since we are not given data from last year. Assume each month has at least one purchase.</p><figure><img alt="The table contains — user’s id, date purchased and purchase amount." src="https://cdn-images-1.medium.com/max/1024/1*_6JQqadQnOqC7n4OkWk6Lw.png" /><figcaption>Amazon_purchases</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3OTk81j8e2ujuVS6NKPOtA.png" /><figcaption>Preview of the table.</figcaption></figure><p>As we can see that the date-time field contains date wise purchase. So if we want to calculate the monthly rolling metric, we should sum up all the day’s purchase to a month’s purchase by using sum() function on purchase amount and group by clause on date-time field.</p><pre>select  to_char(created_at,&#39;YYYY-MM&#39;) as year_month <br>        ,sum(purchase_amt) as sum_purchase_amt<br>from amazon_purchases<br>WHERE purchase_amt &gt;=0                   -- excluding the negative purchase<br>group by 1<br>order by 1;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gn-ToayMf5xirKJKeXBx9w.png" /><figcaption>Output result of above query</figcaption></figure><p>Now we want to calculate the rolling average as we now have got purchase amount for every month. We can now use Window functions — ROWS BETWEEN clause to specify 3 month rolling window and AVERAGE() function to calculate the average monthly purchase and use above query as sub query to get the final results.</p><pre>SELECT year_month<br>        ,AVG(sum_purchase_amt) OVER (ORDER BY year_month ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS three_month_rolling_avg<br>FROM<br>(SELECT  to_char(created_at,&#39;YYYY-MM&#39;) AS year_month <br>        ,sum(purchase_amt) as sum_purchase_amt<br>FROM amazon_purchases<br>WHERE purchase_amt &gt;=0<br>GROUP BY 1) a<br>ORDER BY 1;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ezIFeqvz9Pw31urm4IX-ww.png" /><figcaption>Output result of above query.</figcaption></figure><p>😊 If you like this article 😊, please give me a clap 👏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd2d968c24d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>