Sql查询减法 [英] Sql query for substraction
问题描述
我在一个表TRANS中有两列source_id和Qty 。
Source_id数量
2002 100
2002 200
2002 500
2002 -500
i想要获取 此 source_id的余额 100 + 200 = 300 因为(-500 + 500 = 0 )
如何编写查询 for this
我可以显示 100 和 200 saparate 两行 as balance
我的尝试:
i有两个列苏rce_id和Qty在一个表TRANS中。
来源_数量
2002 100
2002 200
2002 500
2002 -500
i想要获得此source_id的余额,即100 + 200 = 300,因为(-500 + 500 = 0)
如何为此
写一个查询,我可以在两行中显示100和200 saparate作为余额
< blockquote>你应该使用 SQL GROUP BY语句。
SELECT [Source_id],SUM([Qty]) FROM [YourTableName]
GROUP BY ([Source_id])
我可以在两行中显示100和200 saparate作为余额
我无法明白这一点。
i have two columns source_id and Qty in one table TRANS.
Source_id Qty
2002 100
2002 200
2002 500
2002 -500
i want to get balance of this source_id which is 100+200=300 because (-500+500=0)
how can i write a query for this
and can i show 100 and 200 saparate in two lines as balance
What I have tried:
i have two columns source_id and Qty in one table TRANS.
Source_id Qty
2002 100
2002 200
2002 500
2002 -500
i want to get balance of this source_id which is 100+200=300 because (-500+500=0)
how can i write a query for this
and can i show 100 and 200 saparate in two lines as balance
You should use SQL GROUP BY Statement.
SELECT [Source_id], SUM([Qty]) FROM [YourTableName] GROUP BY([Source_id])
"and can i show 100 and 200 saparate in two lines as balance"
I am unable to understand that.
这篇关于Sql查询减法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!