Karlee  Will

Karlee Will

1624694100

How to Use Group By and Partition By in SQL

Introduction

When I first learned SQL, I had a problem of differentiating between PARTITION BY and GROUP BY, as they both have a function for grouping. I believe many people who begin to work with SQL may encounter the same problem. Therefore, in this article I want to share with you some examples of using PARTITION BY, and the difference between it and GROUP BY in a select statement.

Exploration

Sample Data

Firstly, I create a simple dataset with 4 columns. The df table below describes the amount of money and type of fruit that each employee in different functions will bring in their company trip.

Figure 1: df table

Figure 2: df information

#data-analytics #sql #group by #partition by

How to Use Group By and Partition By in SQL