SQL Server Stored Procedure Combining 2 table results -
i have 2 tables:
customertransaction
id (int auto int) customername (varchar) customernumber (int) date (date) weeklyamount (int)
customers:
customername (varchar) customernumber (int) customertype (int) customerdate (date)
this database not normalized, , can not change it. customername
, need do:
i need result show 1 table of information customers
each row matches customer number. in customertransaction
, merely grouping of total sums per customername
of amount.
i using:
select customernumber, sum (weeklyamount) total customers.records group customernumber;
to sum of each customernumber
. problem can not include customername
in group by. name of customers change on time. told grab data customers
, result above , match customernumbers
the problem not know stored procedure. know how done? need rows matched.
select customernumber, sum (weeklyamount) total customers.records group customernumber;
what customers.records
? that's bit confusing. apart that, i'd answer
select c.*, sq.total ( select customernumber, sum(weeklyamount) total customerstransaction group customernumber ) sq inner join customers c on c.customernumber = sq.customernumber
if that's not you're looking for, have rephrase question. it's bit hard understand actual problem is. i'd write query bit different, should deal non-normalization issue.
Comments
Post a Comment