Hi all
I have a table which stores total revenue, by day, for a number of businesses - a bit like this:
id - INT, PRIMARY
date - DATE
businessname - VARCHAR (30)
totalrevenue - DECIMAL(12,2)
The problem with this is that I update the revenue regularly - more than once a day, which generates mulitple rows per day.
I could delete the existing rows each time I update the revenue for that date, but that seems a bit of a workaround.
I could use UPDATE WHERE date=today. Would that cause an insert if revenue data did not exist for a give date, or would I need to run a query first then INSERT if the data did not exist, and UPDATE if it did?
Or would it be 'best practice' to store the data a different way - ie:
id (PRIMARY
date - DATE
businessname1totalrevenue - DECIMAL(12,2)
businessname2totalrevenue
businessname3totalrevenue
?
I'd rather keep the table designed as it is for simplicity but if the latter method would be considered the better way it would be quite easy to change.
Thanks!
Simon