Self-joining SQL statement with calculated data

advertisements

I have a table with the following data:

id  date    name    schedulenum paymentamt
1   12/2/2014   AB  077LR10 100
2   12/2/2014   AN  077LR10 200
3   12/2/2014   CD  077LR10 300
4   3/10/2015   AN  083LR12 200
5   3/10/2015   WC  083LR12 500
6   5/20/2015   AB  105LR20 200
7   5/20/2015   CD  105LR20 150
8   5/20/2015   RH  105LR20 150
9   5/20/2015   RG  105LR20 400

And I would like to write a query that would bring back the following results:

schedulenum paymentamt
077LR10 600
083LR12 700
105LR20 900

Basically I need to create a SQL statement that selects data from Table A that will result in 2 columns. The first column would be a unique schedule number (i.e., 'schedulenum' - there are multiple rows with the same schedulenum) and a total payment amount ('paymentamt') per schedulenum (each row will have a different 'paymentamt'). I think this would require a self-join but not sure how to do it.


Use a group by when getting sums from one table.

select schedulenum, sum(payment) from mytable
where schedulenum = x
group by schhedulenum

...

select schedulenum, sum(payment) from mytable
group by schhedulenum
order by schedulenum