Database design - how do I track information over time and query a table for latest data?

前端 未结 5 1362
名媛妹妹
名媛妹妹 2021-01-15 16:01

We are trying to track our applications in our department and our unit test usage so I have created a database to keep track of this. I have an Applications

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-15 16:21

    Any of these 2 options will work for your scenario:

    1 have the logic that adds the new unit test count for the application, insert the record in the history + update the application record's unit test count. Then use a simple select over the application records - history records have nothing to do in this scenario. This is best if you'll have a huge amount of records in the history.

    2 use this query against the UnitTestTracking table directly

    select application_id, unittestcount from UnitTestTracking u1 
    where date_added = ( 
       select max(date_added) from UnitTestTracking u2 
       where u1.application_id = u2.application_id 
    )
    

提交回复
热议问题