Query to display spent credits from transactional table

后端 未结 2 534
萌比男神i
萌比男神i 2021-02-12 21:55

I am working with a table that contains credit transactions where I want to display who\'s credits were spent when a sale is made.

In the table:

  • Cre
2条回答
  •  青春惊慌失措
    2021-02-12 22:51

    since you mentioned there will be 4 to 5 million records per year, even if this can be done by query it will be an slow query.

    I would suggest to have another table like creditSpent which contains (PurchaseCreditLogId , additionCreditLogId, Amount)

    And in the time of inserting purchases, find all records, calculate the amount that should be reduced from each one and store that information in that table

    Then when you are running your report you can do a simple query on this table

提交回复
热议问题