mysql - New table (with derived_data) or SQL query? -
from best-practice point of view, better create new table in database derived_data field other tables, or calculate using sql-query everytime?
details: more precicely, have table orders(id_order,date,time,sum)
, want track daily profits , preview them everytime administrator selects drop-down menu. shall make sql-query everytime asks it, or new table profits(date,day_profit)
with derived_data field takes value other tables?
for simple calculations (a+b
), them in select
.
for aggregates (count(sales), sum(revenue)
) results regularly calculate, build "summary table(s)".
for example, daily counts, totals, etc, broken down region
. otherwise take group by
, etc.
note can compute weekly or monthly totals daily table, not build more tables.
for thousand rows, not important; million or billion vital performance in "data warehousing".
keep in mind summary table no-no (to database purists) since holds 'redundant' data. policies should avoid letting out of sync.
Comments
Post a Comment