简体   繁体   English

用于每日报告的 MYSQL 数据结构

[英]MYSQL Data Structure for Daily Reporting

I built a daily report application for an automotive dealer group with 24 locations.我为一个拥有 24 个地点的汽车经销商集团构建了一个每日报告应用程序。 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.您可以更改daily_reports表以添加新字段,然后开始向其中添加数据。

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.您可以通过创建合并报告表(例如montly_reports ),在那里添加所有每日报告的总和,并在一段时间后修剪daily_reports来减少存储的数据量。 This way you will have daily reports for the last x months, and consolidated reports from since the start of data collection.通过这种方式,您将获得过去 x 个月的每日报告,以及自数据收集开始以来的合并报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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