azzazzello
Technical User
Hi,
Suppose I have 2 tables.
One is called "detail"
This table is useful for research, however I expect that 95% of the queries will be grouping by date and account_id. Since there are thousands of stocks, aggregation would get rid of a huge number of rows. I therefore would like to create a table called "summary" to deal with the vast majority of the queries. The table would look like this
You can see that summary is the same as "detail" except that there is no "stock" column.
"detail" table will have inserts and occasional updates to it. I would like to make it so that every time there is an insert/update to "detail", a relevant insert/update takes place in the "summary" table. New entries are easy - I can create a trigger/stored procedure to update the summary table with new values. However, what can I do for updates? They will clear away old values and set new ones. How can I handle that? The only thing that comes to mind is update the "summary" table with a select from the detail one once in a while, however that means there is potentially stale/incorrect data in the summary table.
I'd love to listen to ideas
Suppose I have 2 tables.
One is called "detail"
Code:
date DATE
account_id int
stock varchar(10)
trades int
pnl int
PRIMARY KEY (date,account_id,stock)
This table is useful for research, however I expect that 95% of the queries will be grouping by date and account_id. Since there are thousands of stocks, aggregation would get rid of a huge number of rows. I therefore would like to create a table called "summary" to deal with the vast majority of the queries. The table would look like this
Code:
date DATE
account_id int
trades int
pnl int
PRIMARY KEY (date,account_id)
You can see that summary is the same as "detail" except that there is no "stock" column.
"detail" table will have inserts and occasional updates to it. I would like to make it so that every time there is an insert/update to "detail", a relevant insert/update takes place in the "summary" table. New entries are easy - I can create a trigger/stored procedure to update the summary table with new values. However, what can I do for updates? They will clear away old values and set new ones. How can I handle that? The only thing that comes to mind is update the "summary" table with a select from the detail one once in a while, however that means there is potentially stale/incorrect data in the summary table.
I'd love to listen to ideas