sql server - Calculated column within a JOIN using T-SQL -


i display sum of total amount of applications person has made.

i have tried this:

select distinct custid, firstname, appid, appdate, amount custtable join apptable on custid = appid 

i have lots of rows per customer , sum total application amount per customer

at moment see this:

1 | jon | app_1 | 200  1 | jon | app_2 | 200 1 | jon | app_3 | 200 1 | jon | app_4 | 200 

but want (ideally date ranges):

1 | jon | app_1 | 800 

you can this:

select custid, firstname, sum(amount) custtable join apptable on custid = appid group custid, firstname 

which return this:

1 | jon | 800 

additionally, can have date range this:

select custid, firstname, sum(amount),         min(appdate) firstdate, max(appdate) lastdate,  custtable join apptable on custid = appid group custid, firstname 

which return this:

1 | jon | 800 | 2013-01-01 | 2013-01-28 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -