I would really like to know how web sites decide what ad to show to a user and how many times.
I think there must be a table Ads (id, url, ...) which is linked to a table Users by many to many relationship via table Ads2Users (ad_id, user_id, shown_count, clicked_count). So that each time a user is served a particular ad we find (or create) a record in Ads2Users and increment the counter.
Seems simple if we consider registered users and those who do not erase cookies.
Now the question: is that how it works?