Microsoft
Software
Hardware
Network
Question : SQL query
I am writting a SQL query. Below is the sample table. The result i want is for each customer, difference of sum of by and sum of sell.
Table:
customer trtype amount
0001 by 10000
0001 by 2000
0001 by 500
0001 sl 3000
0001 sl 2000
0002 by 60000
0002 by 4000
0002 by 500
0002 sl 3000
0002 sl 2000
example:
0001 : (10000+2000+500) - (3000+2000) = 12500-5000 = 7500
0002 : (60000+4000+500)-(3000+200
0) = 64500-5000 = 59500
Result should be
0001 - 7500
0002 - 59500
Answer : SQL query
try this
Select A.customer, B.Name, sum(case when trtype='by' then amount else -amount end)
from tablename A join customerTable B
on A.customer = b.code
group by A.customer, B.Name
Random Solutions
Column headings in crosstab queries part 2
Remote Desktop between 2 Win XP Pro machines on a LAN. How much more simple could it be and how hard is it for me!
copy/paste capacity
Word Macro problem, dynamic image resize macro
Help with LDAP query
How to get variable value in domodal dailog?
BAR CHART in EXCEL data is upside down..
Ms Access to SQL Server DSN or connection string
Deploy a change in registry in a terminal server farm
How would I extract one of each number in an excel column that contains many copies of hundreds of numbers?