Hi there, this problem should have a simple solution, i just cant think of it ..
got two tables, tblSales and tblInvoiceItems, invoice items has a costprice in there - product cost price
tblsales works fine when theres only one occurance of this costprice but when we create another invoice and change the costprice, tblsales now has duplicated records (which i understand) with all fields being the same except showing both the old costprice and the new one..
i want to average the costprice out so that the query only returns the average of both records
i.e. say old costprice was 10
sales table would have
transactionday costprice product id
Today 10 A100
if i add another invoice (say cost price now changes) to 12
sales then would have two records
transactionday costprice productid
today 10 A100
today 12 A100
i want it to just have
transactionday costprice productid
today 11 A100
i know i need to use AVG but not sure where, do i need to average on the duplicate records ? ive tried using AVG on costprice but it still pulls up the same number of records, which im thinking is cause im averaging it in the wrong place as its only averaging one record
ive tried using AVG elsewhere to try to get it to work but no luck!
if anyone can help i would be appreciative!
got two tables, tblSales and tblInvoiceItems, invoice items has a costprice in there - product cost price
tblsales works fine when theres only one occurance of this costprice but when we create another invoice and change the costprice, tblsales now has duplicated records (which i understand) with all fields being the same except showing both the old costprice and the new one..
i want to average the costprice out so that the query only returns the average of both records
i.e. say old costprice was 10
sales table would have
transactionday costprice product id
Today 10 A100
if i add another invoice (say cost price now changes) to 12
sales then would have two records
transactionday costprice productid
today 10 A100
today 12 A100
i want it to just have
transactionday costprice productid
today 11 A100
i know i need to use AVG but not sure where, do i need to average on the duplicate records ? ive tried using AVG on costprice but it still pulls up the same number of records, which im thinking is cause im averaging it in the wrong place as its only averaging one record
ive tried using AVG elsewhere to try to get it to work but no luck!
if anyone can help i would be appreciative!