Write a query to populate total_sal column value in the below format from the above input data from the table
Write a query to populate total_sal column value in the below format from the above input data from the table
Input:
id dept sal total_sal
1 10 100 100
2 10 200 300
8 10 200 500
3 20 200 200
4 20 300 500
5 30 400 400
Output:
Solution:
# SQL query to add a cumulative sum of the "sal" column, partitioned by "dept" and ordered by "id", to the "lux" DataFrame.
select *,sum(sal) over (partition by dept order by id)as total_sal from lux
Here, lux is table name.
Comments
Post a Comment