<?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 Krithika Sangareddypeta on Medium]]></title>
        <description><![CDATA[Stories by Krithika Sangareddypeta on Medium]]></description>
        <link>https://medium.com/@kr13thika?source=rss-fe43fad5fe6e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Gv1QOkP1EnSRFBT9pkyu2Q.jpeg</url>
            <title>Stories by Krithika Sangareddypeta on Medium</title>
            <link>https://medium.com/@kr13thika?source=rss-fe43fad5fe6e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 08:15:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kr13thika/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[Introductory Guide to SQL]]></title>
            <link>https://medium.com/@kr13thika/introductory-guide-to-sql-864bee412d14?source=rss-fe43fad5fe6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/864bee412d14</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Krithika Sangareddypeta]]></dc:creator>
            <pubDate>Mon, 23 Jan 2023 21:41:06 GMT</pubDate>
            <atom:updated>2023-01-23T21:41:06.897Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is SQL?</h3><p>SQL stands for “Structured Query Language” . It is used for storing the information in tabular form of rows and columns to form a relational database. Several SQL operations such as store, update, remove, search, and retrieve can be performed on the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*a-LwNkTpALpm9IPDqLtweA.png" /></figure><h3><strong>Dense rank SQL</strong></h3><p>In SQL, the DENSE_RANK () function is used to assign a rank to each row within a result set, with no gaps in the ranking. The DENSE_RANK () function is similar to the RANK () function, but will always return a unique rank for each distinct row, even if multiple rows have the same value.</p><p>The syntax for the DENSE_RANK () function is as follows:</p><p>DENSE_RANK () OVER (ORDER BY column1 [ASC|DESC], column2 [ASC|DESC], …)</p><p>This function takes one or more columns as its argument and returns a unique rank for each row based on the values in those columns. The “OVER” clause is used to specify the window of the result set over which the ranking should be applied. The “ORDER BY” clause is used to specify the order in which the ranking should be applied.</p><p>For example, the following query returns the names of all employees in a table, along with their salary and a dense rank based on their salary:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/0*qIc6ku2ZASVW_f8D" /></figure><p>This query would return a result set with columns for the name, salary, and rank of each employee, with the employees ranked in descending order based on their salary.</p><p>In this example, Dense Rank is used to find the ranking of the employee’s salary. Dense rank is used to get the unique ranking for each distinct row in the table, it will assign unique rank to the rows even if the values of the rows are same.</p><h3><strong>Order of execution in SQL</strong></h3><p>The order of execution in SQL, also known as the “query execution order,” refers to the sequence of steps that the database management system (DBMS) follows when processing a SQL statement. Understanding the order of execution is important for writing efficient and effective SQL queries.</p><h3><strong>Different Clauses in SQL</strong></h3><p>The general order of execution in SQL is as follows:</p><p>1. <strong>FROM clause: </strong>The DBMS retrieves the data from the specified tables in the FROM clause.</p><p>2. <strong>JOIN clause: </strong>If a JOIN clause is present, the DBMS combines the rows from the different tables based on the join condition.</p><p>3. <strong>WHERE clause: </strong>The DBMS filters the rows based on the conditions specified in the WHERE clause.</p><p>4. <strong>GROUP BY clause: </strong>If a GROUP BY clause is present, the DBMS groups the rows based on the specified columns.</p><p>5. <strong>HAVING clause: </strong>The DBMS filters the groups based on the conditions specified in the HAVING clause.</p><p>6. <strong>SELECT clause: </strong>The DBMS retrieves the specified columns from the filtered and grouped rows.</p><p>7. <strong>DISTINCT clause: </strong>If the DISTINCT clause is present, the DBMS removes duplicate rows.</p><p>8. <strong>ORDER BY clause: </strong>If the ORDER BY clause is present, the DBMS sorts the result set based on the specified columns.</p><p>For example, consider the following query:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/0*w3fyxPgKwk-PI4Hg" /></figure><p><strong>ORDER BY SUM (salary) DESC</strong>; In this query, the DBMS will first retrieve all the data from the “employees” table, then it will filter the rows based on the hire_date condition. Next, it will group the rows by department and filter the groups based on the HAVING clause. Then it will select the department and SUM (salary) columns, remove any duplicate rows and sort the results based on the SUM(salary) column in descending order.</p><p>It is important to note that some database management systems may have slight variations in the order of execution and may also optimize the query execution using techniques such as indexing and caching. However, the general order of execution described above applies to most SQL implementations.</p><h3><strong>Advance SQL</strong></h3><p><strong>Advanced SQL</strong> refers to the use of more complex and powerful SQL features and techniques to perform tasks such as data analysis, data manipulation, and data management. Some examples of advanced SQL features and techniques include:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*9UFKonYULL_w7YMZqVjFXw.png" /></figure><ol><li><strong>Subqueries: </strong>These are queries that are nested within another query and are used to retrieve data that is related to the outer query. For example, a subquery can be used to find the names of all employees who work in the same department as a specified employee.</li><li><strong>Common Table Expressions (CTEs): </strong>These are named temporary result sets that can be used within a SELECT, INSERT, UPDATE, or DELETE statement. CTEs are useful for breaking down complex queries into smaller, more manageable pieces.</li><li><strong>Window Functions: </strong>These are functions that perform calculations over a set of rows, called a “window,” that are related to the current row. Examples of window functions include RANK (), DENSE_RANK(), and ROW_NUMBER().</li><li><strong>Stored Procedures</strong>: These are pre-compiled SQL statements that can be executed with a single call. Stored procedures can take input parameters, and can return multiple result sets, making them useful for encapsulating complex logic or data validation.</li><li><strong>Triggers: </strong>These are special procedures that are automatically executed in response to certain events, such as inserting, updating or deleting data.</li><li><strong>Cursor: </strong>A cursor is a control structure that allows traversal over the records in a database. A cursor can be used to retrieve a single row at a time from a result set and can be used to update or delete rows one at a time.</li><li><strong>Transactions: </strong>Transactions are a way of grouping a set of SQL statements together so that they are treated as a single unit of work. If any of the statements in a transaction fail, the whole transaction is rolled back, and the database is returned to the previous state.</li><li><strong>Partitioning: </strong>Partitioning is a technique used to divide a large table into smaller, more manageable pieces. This can help improve query performance and manageability of large datasets.</li></ol><p>These are some examples of advanced SQL features and techniques, but there are many more available depending on the specific database management system you are using. To become proficient in advanced SQL, it is important to have a good understanding of the basics of SQL. Additionally, it is recommended to practice with real-world examples and use real-time cases to get a good understanding of the advanced SQL concepts.</p><h3><strong>Pivot table in SQL</strong></h3><p>A pivot table is a way of transforming data from a “long” format to a “wide” format in SQL. It is used to summarize and analyze large sets of data by rotating rows into columns and aggregating data. The resulting table, called a pivot table, provides a more compact and intuitive representation of the data.</p><p>The basic syntax for creating a pivot table in SQL is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/0*64ZrvCU20OVMNaJX" /></figure><p><strong>“Table name” </strong>is the name of the table to be pivoted, is the column that contains the values that will be used to create the columns in the pivot table, and <strong>list_of_values </strong>is a list of the values that will be used to create the columns in the pivot table.</p><p>For example, consider the following table of sales data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/0*VIP3zkXPRxuZblKK" /></figure><p>To create a pivot table that shows the total sales for each product by month, we can use the following query:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/0*kmcnZf_bMYs9QFZH" /></figure><p>This query will return the following pivot table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/0*mFxHFDLcbEhwO4Oo" /></figure><p>It’s important to note that not all database management systems support pivot tables natively. Some database management systems, such as MySQL, do not have a built-in pivot function, and the pivot table must be created using a combination of SQL statements such as GROUP BY, CASE, and UNION.</p><p>In summary, a pivot table is a way of transforming data from a “long” format to a “wide” format in SQL. It is used to summarize and analyze large sets of data by rotating rows into columns and aggregating data, providing a more compact and intuitive representation of the data. Some databases have built-in pivot function, while others may require additional statements to accomplish the same task.</p><h3><strong>Lead and lag in SQL</strong></h3><p>In SQL, the <strong>LEAD ()</strong> and <strong>LAG()</strong> functions are used to access data from a subsequent or preceding row within a result set, respectively. These functions are commonly used to compare values from multiple rows, and are particularly useful for working with data that is ordered by one or more columns.</p><p>The LEAD() function is used to retrieve the value from a specified column in the next row within the result set. The basic syntax for the LEAD() function is as follows:</p><p>LEAD(column_name, offset, default_value) OVER (ORDER BY column1 [ASC|DESC], column2 [ASC|DESC], …)</p><p>Here, <strong>column_name </strong>is the name of the column whose value you want to retrieve, <strong>offset </strong>is the number of rows ahead of the current row to retrieve the value from, and <strong>default_value </strong>is the value to return if there is no next row in the result set. The “OVER” clause is used to specify the window or partition of the result set over which the function should be applied, and the “ORDER BY” clause is used to specify the order in which the function should be applied.</p><p>For example, the following query returns the names and salaries of all employees, along with the salary of the next employee in the result set:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/0*sJjIbHRIAeXORFXg" /></figure><p>This query would return a result set with columns for the name, salary, and next_salary of each employee, with the employees ordered by salary.</p><p>On the other hand, the <strong>LAG() </strong>function is used to retrieve the value from a specified column in the previous row within the result set. The basic syntax for the LAG() function is similar to the <strong>LEAD()</strong> function but with the word LAG instead of LEAD.</p><p>For example, the following query returns the names and salaries of all employees, along with the salary of the previous employee in the result set:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/0*6p7wrsiD5oHlwC4w" /></figure><p>This query would return a result set with columns for the name, salary, and prev_salary of each employee, with the employees ordered by salary.</p><p>It’s important to note that the LEAD() and LAG() functions are not supported by all database management systems, and some may have different syntax or functionality. Additionally, the use of these functions may result in a significant performance impact if not used carefully with large datasets.</p><h3><strong>What is Normalization in SQL?</strong></h3><p><strong>Normalization</strong> is the process of organizing data in a relational database to minimize data duplicity and improve data integrity. The goal of normalization is to ensure that each table in a database stores only the data that is necessary for a specific purpose, and that the data is organized in a way that minimizes data duplication and maximizes data consistency.</p><p>There are several normal forms that are used to define the level of normalization for a database, with the most commonly used normal forms being first normal form (1NF), second normal form (2NF), and third normal form (3NF).</p><p><strong>1NF (First Normal Form)</strong> — A table is in 1NF if it meets the following criteria:</p><p>∙ Each table has a primary key, which is a unique identifier for each row in the table.</p><p>∙ Each column in the table contains only atomic (indivisible) values.</p><p>∙ There are no repeating groups of data within the table.</p><p><strong>2NF (Second Normal Form)</strong> — A table is in Second Normal Form if it meets the following criteria:</p><p>∙ The table is in 1NF.</p><p>∙ All non-primary key columns in the table are dependent on the primary key.</p><p><strong>3NF (Third Normal Form) </strong>— A table is in 3NF if it meets the following criteria:</p><p>∙ The table is in 2NF.</p><p>∙ There are no transitive dependencies in the table.</p><p>Normalization can help to improve the performance, scalability, and maintainability of a database by reducing data duplication, reducing the need for complex relationships between tables, and making it easier to enforce data integrity constraints.</p><h3>SQL for Data Science</h3><p>SQL is a powerful and widely-used tool for data science, as it allows for the manipulation, retrieval and analysis of large datasets. SQL is particularly useful for data exploration and cleaning, as well as for creating and querying data subsets that can be used for analysis and modeling.</p><p>One of the main use cases of SQL in data science is data exploration, where a data scientist uses SQL to retrieve and examine the data in order to understand its structure, quality and relationships. This is often done by running SELECT statements to retrieve specific columns, filtering data using a WHERE clause and grouping data using GROUP BY clause.</p><p>Another important use case of SQL in data science is data cleaning, where a data scientist uses SQL to identify and correct errors and inconsistencies in the data. This can include tasks such as filling in missing values, removing duplicate records, and converting data types.</p><p>SQL is also a powerful tool for creating data subsets that can be used for analysis and modeling. A data scientist can use SQL to filter and aggregate data based on specific criteria, and then use the resulting data subset for further analysis and modeling.</p><p>In addition to these use cases, SQL can also be used to perform more advanced data manipulation and analysis tasks. This can include tasks such as calculating running totals, creating pivot tables, and using window functions to perform calculations on a set of rows within a result set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*f_ApXE4hTX2bu0Kr6H5HCQ.png" /></figure><p>It’s important to note that SQL is not the only tool used for data science, as other programming languages such as Python and R are also commonly used for data analysis and modeling tasks. However, SQL is an important tool for data science as it allows for the efficient manipulation and analysis of large datasets, making it an essential tool for working with relational databases.</p><h3>Complex SQL queries</h3><p>Complex SQL queries refer to SQL statements that involve multiple tables, subqueries, and advanced features such as joins, window functions, and aggregation. These types of queries can be used to perform advanced data analysis and manipulation tasks and can be more challenging to write and understand than simple queries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*ocH2rRepubmOFksgDnYNQw.png" /></figure><p>Some examples of complex SQL queries include:</p><ol><li><strong>Joins:</strong> A join is used to combine data from two or more tables based on a common column. Complex joins can involve multiple tables, outer joins, and self-joins.</li><li><strong>Subqueries</strong>: A subquery is a query that is nested within another query. Complex subqueries can involve multiple levels of nesting, correlated subqueries, and subqueries in the SELECT, FROM, WHERE, and HAVING clauses.</li><li><strong>Window Functions:</strong> Window functions are used to perform calculations on a set of rows within a result set. Complex window functions can involve multiple functions, partitions, and orderings.</li><li><strong>Grouping and Aggregation:</strong> Complex queries can use multiple levels of grouping and aggregation, and can involve multiple aggregate functions and grouping columns.</li><li><strong>Recursive Queries:</strong> Some database management systems support recursive queries which allows a query to reference itself. This can be used to solve problems such as hierarchical data or generating sequences</li><li><strong>UNION and EXCEPT:</strong> These are set operations that can be used to combine or compare the results of multiple SELECT statements.</li><li><strong>UNION ALL:</strong> UNION ALL combines the results of two or more SELECT statements into a single result set, with duplicates included</li><li><strong>Stored Procedures:</strong> Stored Procedures are pre-compiled SQL statements that can be executed multiple times with different input parameters. This can be useful for encapsulating complex logic or for performance optimization.</li></ol><h3>Conclusion:</h3><p>These are just a few examples of the types of complex SQL queries that can be used to perform advanced data analysis and manipulation tasks. Writing and understanding complex SQL queries can be challenging, but they can be very powerful and flexible tools for working with large and complex datasets.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=864bee412d14" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get to Know Me!]]></title>
            <link>https://medium.com/@kr13thika/get-to-know-me-508910cb5d9d?source=rss-fe43fad5fe6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/508910cb5d9d</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[sql-joins]]></category>
            <category><![CDATA[sqlalchemy]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Krithika Sangareddypeta]]></dc:creator>
            <pubDate>Mon, 23 Jan 2023 20:15:59 GMT</pubDate>
            <atom:updated>2023-01-23T20:15:59.925Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi, I am Krithika Sangareddypeta and I am a data scientist. I love writing articles on the current issues and fields related to the upcoming technologies. I believe in spreading happiness and smiles around me as world is such a small place to live, why not make it a fun space!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=508910cb5d9d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>