Say I was building an e-commerce website, how would I go about recording the number of products sold each day to show later on, I know I could save the amount of items in stock and put it into a database then see whether it has decreased the next day which I suppose is inevitably the solution, but imagine a store owner who wanted to see how much of any product he had sold in the last year, bearing in mind he has 1000 products, would this require 1000 columns with 365 rows? Am I thinking about this wrong or is this really the case? I know there are extensions you can download for things such as os-commerce and Magento among others which have this kind of functionality and I was wondering whether they shared a common approach or came up with something else?
So basically I’m looking to generate reports and statistics, how is this usually done, does it require huge tables with every daily change for every product?
My first inclination would be to treat each transaction as a row, with the name of the product sold in one of the columns. To meet your other requirements, a date column would be necessary to query if the item was sold between two dates.
You can then do any number of manipulations to this table.