<?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 Cyriac k pazhemadom on Medium]]></title>
        <description><![CDATA[Stories by Cyriac k pazhemadom on Medium]]></description>
        <link>https://medium.com/@kpazhemadomcyriac9?source=rss-b91d300b71fe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Cyriac k pazhemadom on Medium</title>
            <link>https://medium.com/@kpazhemadomcyriac9?source=rss-b91d300b71fe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 18:56:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kpazhemadomcyriac9/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[ORDER OF EXECUTION]]></title>
            <link>https://medium.com/@kpazhemadomcyriac9/order-of-execution-78bd2646079c?source=rss-b91d300b71fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/78bd2646079c</guid>
            <dc:creator><![CDATA[Cyriac k pazhemadom]]></dc:creator>
            <pubDate>Thu, 02 Apr 2026 16:13:26 GMT</pubDate>
            <atom:updated>2026-04-02T18:44:28.786Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>FROM</li><li>JOIN</li><li>WHERE</li><li>GROUP BY</li><li>HAVING</li><li>SELECT</li><li>WINDOW FUNCTIONS</li><li>ORDER BY</li><li>TOP</li></ol><p>A) FROM- The table from which the rows should be selected is decided first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R4yLk86n9-PNOjpi8QiyFw.png" /></figure><p>B) JOIN- A table is joined with another table based on the ON condition( based on columns from both tables that satisfy a condition)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Cc7VsmvJtNiGeT2RHGe-g.png" /></figure><p>C) WHERE- The table rows are filtered. The table post JOIN condition is filtered based on column values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9IFJPBaUBYOxEeJ5Z0RInw.png" /></figure><p>D) GROUP BY- Collapse the rows into a single row. Hence it is necessary to aggregate columns. The columns used for GROUP BY should be used in the SELECT along with the column aggregations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rgtr3sVEzeGsYIYknARe9w.png" /></figure><p>LEFT JOIN and WHERE condition gives result similar to INNER JOIN. So we have to use AND condition instead of WHERE. Then we use GROUP BY, so in the above example GROUP BY based on dept_ name only gives HR . If we had used WHERE condition instead of AND, GROUP BY will not have NULL.</p><p>E) HAVING- Once the GROUP BY is done and aggregate columns are obtained, we can filter the aggregate columns using HAVING. Only aggregate columns can be filtered using HAVING not the original columns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FTL_ilMao2aYyrHojtwM4A.png" /></figure><p>F) WINDOW FUNCTION- One the SELECT is done, the WINDOW function is executed over the result of SELECT. Since HAVING is executed before the WINDOW FUNCTION, it works only on those collapsed rows which are left after HAVING is executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eijJkvBfMkrSn_12hf8GDA.png" /></figure><p>COUNT(*) is executed first then the WINDOW FUNCTION AVG(COUNT(*)) OVER ().</p><ul><li>**********************COMMON MISTAKES******************</li><li>Never use aggregate functions (SUM, MIN, MAX )with WHERE . You have to use a column.</li><li>HAVING should used filter aggregate result, but we can also use it to filter GROUPED COLUMN</li><li>You cannot use WINDOW FUNCTIONS with WHERE</li><li>We cannot use SELECT ALIAS in WHERE because WHERE is executed before SELECT, but we can use the alias in ORDER BY. This is because ORDER BY is executed last.</li><li>COUNT(* ) this counts all rows even NULL, but COUNT( column_ name) ignores NULL values.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78bd2646079c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WINDOW FUNCTION IN SQL SERVER]]></title>
            <link>https://medium.com/@kpazhemadomcyriac9/window-function-in-sql-server-c9fc25f63441?source=rss-b91d300b71fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9fc25f63441</guid>
            <category><![CDATA[sql-server-window-functio]]></category>
            <category><![CDATA[over]]></category>
            <dc:creator><![CDATA[Cyriac k pazhemadom]]></dc:creator>
            <pubDate>Tue, 10 Mar 2026 10:25:30 GMT</pubDate>
            <atom:updated>2026-03-10T17:01:57.983Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>DEFINITION: When we use GROUPBY, the rows are collapsed to produce a single row output. But using window functions, we can carry out calculations on a window which is created using OVER( ).</strong></blockquote><figure><img alt="The partition is done over brand, within each brand the maximum product price is displayed." src="https://cdn-images-1.medium.com/max/1024/1*pQg7jBrsIDYr6mLPp1Zl3A.png" /><figcaption><strong>The partition is done over brand, within each brand the maximum product price is displayed.</strong></figcaption></figure><blockquote><strong>ROW_NUMBER( )- A row number is assigned for the rows in each window. Unlike the RANK(), here just numbers are assigned to the rows, factor such as ties are not taken into account.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vs9JX3VIBm3_r_SmkTLRKA.png" /><figcaption>First the row number is assigned for partition created based on each brand. The within this, row numbers are allocated. Next, we use CTE to assign a name to the subquery which can be filtered based on a condition.</figcaption></figure><blockquote><strong>RANK( ) AND DENSE_RANK( )- When we use RANK( ), when there are ties both are assigned the same number, but we skip the next number.</strong></blockquote><p><strong>However, DENSE_RANK( ) does not skip the next number even if there are ties.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pfkFEgAqZCjjPZnVk4XK8w.png" /><figcaption>This shows the difference between rank( ) and dense_rank( ).</figcaption></figure><blockquote><strong>LAG( ) AND LEAD( )- The window function LAG( ) will provide the preceding value and LEAD( ) will provide the value succeeding it.</strong></blockquote><p><strong>We can provide two other arguments, LEAD( column, row_ count, default value). row_ count will instruct how many rows below and default will give what value to be used instead of NULL.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nnI9Xk8AOxdbx6ju9_HbRQ.png" /><figcaption>LAG( product_ name, 2, 0) means provide the product_name in the column, two rows above and use zero instead of NULL.</figcaption></figure><blockquote>FIRST_ VALUE( ) — It will give the first value from the given given window.</blockquote><blockquote>LAST_ VALUE( )- It will give the last value from the given given window.</blockquote><p>When we use LAST_ VALUE( ) we will get incorrect result due to frame. The FRAME are subset within each window. The FRAME is</p><blockquote><strong><em>range between unbounded preceding and current row-</em></strong></blockquote><blockquote><strong><em>so for each row it only considers the first value of that window and current row, so the whole set of rows in that window is not considered.</em></strong></blockquote><p>The FRAME should be changed to <strong><em>range between unbounded preceding and unbounded following row.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vh92nfNzM9hSJFmTM7UzZw.png" /><figcaption>LAST _ VALUE gives incorrect result due to the FRAME.</figcaption></figure><blockquote><strong>LAST _ VALUE with the modified frame.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YJ1jk0_ZJtpyy50Kvj2BSA.png" /><figcaption>We get the correct result when the frame has been modified.</figcaption></figure><blockquote>Ntile( )- Divide the records into n buckets. The priority is given to the first bucket if the division cannot be done uniformly.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EllKfGFiM-GpdbmUXMKQ_A.png" /><figcaption>The records divided in 3 buckets and then each bucket is assigned a Name based on the bucket value.</figcaption></figure><blockquote><strong>CUM _ DIST( )-</strong> The position of the current row based on the ORDER BY condition. For example, for the first row, the position is the ORDER BY is 1. This is divided by the total number of records.</blockquote><p>If there is a tie, then the position of the final record in the tie is divided by total number of records.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ho9yFGrGcJtBxi97qkAXYw.png" /></figure><p>CAST( expression AS datatype)- Convert one datatype to another.</p><p><strong>e.g.. CAST( expression as DECIMAL(10,2))</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gVCLScRLxgbELh16iv3i7A.png" /><figcaption>products in the top 30%</figcaption></figure><blockquote>CUMULATIVE VALUE- Within OVER( ) if we just specify partition by column Name, a window is created and for each row the window function is computed considering the entire set of rows in that particular window.Basically, for all the rows in that window we get the same value. The FRAME is RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING</blockquote><p>However, if we provide ORDER BY then we have a default FRAME :</p><p>RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.</p><p>Therefore, it get the cumulative result.</p><p>If we write RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, for same ORDER BY VALUE are grouped i.e. if there is two rows of the same date with value 100 and 50, both rows will have 150. This is not cumulative.</p><p>ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW- Each row is considered individually even when there are ties, it is not grouped together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OSmRDXcaMc04IuOJ_WXOxQ.png" /><figcaption>Without ORDER BY the FRAME is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9fc25f63441" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>