given a sales table defined as:
CREATE TABLE [dbo].[t_sales](
[sales_id] [int] IDENTITY(1,1) NOT NULL,
[cust_id] [int] NOT NULL,
[sales_amt] [money] NOT NULL,
[sale_date] [datetime] NOT NULL
) ON [PRIMARY]
I need to return the cust_id, sales_amt, and the running total of the sales_amt, which should reset when the cust_id changes. Something like this:
cust_id, amt, running_total
1,50,50
1,25,75
1,50,125
2,25,25
2,50,75
etc.
I've spent hours trying to get this to work, but I'm clearly missing something. Help greatly appreciated.