内部联接的工资总和 [英] Sum of Salary with Inner join
本文介绍了内部联接的工资总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张这样的表
I have a Table like this
Id name salary
1 A 100
2 B 200
3 A 100
4 C 700
5 D 600
6 C 700
我需要使用SQL查询获得此结果像这样
I require this result using SQL query like this
name salary sumofsalary
A 100 100
B 200 300
A 100 400
C 700 1100
D 600 1700
C 700 2400
请查看下一行的所有工资总和行工资
我得到了内部联接获得所需结果的解决方案,但我无法理解查询的行为。我的意思是如何使用内连接。
查询是:
Please see every next row sum of salary is done with the all previous row salaries
I got the solution to get the required result with inner join but i am not able to understand the behavior of query. I mean how it is being done with inner join.
The query is:
select e.name,e.salary,sum(e2.Salary) sal
from Emp e inner join Emp e2
on e.Id>=e2.Id
group by e.Id,e.name,e.salary
请帮助
Please help
推荐答案
考虑在有用的id上连接两个表 - 一个用于计算总和,然后连接到另一个包含所有细节的表。
Think of joining two tables on employeed id - one which is used to compute the sum and then joined to the other which contains all details.
u应该尝试 Google
在cp中查看以下链接: SQL连接的可视化表示
在cp中搜索联接
u should have tried Google
Check this links in cp: Visual Representation of SQL Joins
Search join in cp
嗨...
自行检查代码项目网站....
在以下链接中...您将获得所需答案(在我的帖子中)
小型办公室帐户管理的帐户计算 [ ^ ]
在SQL Server中,第一行最后一列是如何添加第二行列? [ ^ ]
(注意:不能在JOIN概念中解决这个问题)
问候,
GVPrabu
Hi...
Check in Code project site it self....
In the below link.. you will get the required Answer(In my Post)
Accounts calculation for small office accounts management[^]
IN SQL Server, First row Last Column is How to add with second row Columns?[^]
(Note: Not able to Solve this in JOIN Concept)
Regards,
GVPrabu
这篇关于内部联接的工资总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文