Products (productId INT PK, bidCount INT)
Bids(bidID INT PK, productId INT, userId INT, isCounted BIT, created DATETIME)
There is a 1:many relationship between a product and bids.
Each biding cycle lasts for 1 day, so I need to track unique bids per day and update the bidCount column. I set isCounted = 1 for every row that I process during the batch process.
So this is a running total of unique bids for a product throughout the day.
I have a sql job that runs every 5 minutes to update the bidCount.
Steps that I think I need for this query:
- grab all rows that have isCounted = 1
- query#1 build a list of productID and uniqueBidCounts where isCounted = 1 query#2 build a list of productID and uniqueBidCounts where isCounted = 0 query#3 build a list of productID and uniqueBidCounts with the difference between #1 and #2
- update the products table by adding the uniqueBidCounts to the bidCount column using query #3
- set the isCounted = 1 for the list in query#2
Is this the right approach? is this a complicated approach or can it be simplified?
Updated I added the DATETIMe field created, so I will have to filter for the current day, and delete any older bids in another batch job run daily (or in the same process)