简体   繁体   中英

MYSQL Data Structure for Daily Reporting

I built a daily report application for an automotive dealer group with 24 locations. Each day the manager at each location can enter in amount of new and used vehicles sold. Daily, weekend, and monthly empire-wide sales reports are generated from the data.

I used two tables

  • dealerships (id, dealership_name)
  • daily entries (dealer_id, entry_date, new, used).

Everything works fine.

Now, they want to expand the reports to include fields such as gross profit, daily opportunities, test drives, warranties sold, alarms sold. And they want to see daily and monthly reports for each store not just the empire-wide totals.

Should I use separate tables for each dealership, or can I continue use a single table for all the dealerships. If I stick with a single table, it seems that I will have to search the entire database every time I want to generate a report for a single store. As time goes by, and the table increases in size, won't this eventually effect performance?

Don't use a table for each dealership, that's not the way databases are designed. Tables hold data from entities of the same type, not different instances of the same entity. One table for dealerships and another for daily reports is enough. You can just alter the daily_reports table to add the new fields, and start adding data to them.

Don't worry about the tables growing in size, that's what databases are born to do: deal with data. You can reduce the amount of stored data by creating a consolidated report table ( montly_reports , for example), adding the sum of all daily reports there, and pruning the daily_reports after a while. This way you will have daily reports for the last x months, and consolidated reports from since the start of data collection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM