S
S
synapse_people2016-07-11 10:22:46
MySQL
synapse_people, 2016-07-11 10:22:46

How to correctly calculate statistics in MySQL?

Good afternoon.
There is a task - to calculate the statistics of transitions on the referral link and the number of registrations by day.
Now it works like this: pastebin.com/X2HKN3cq
Is it possible to optimize somehow or is this the best option for solving such a problem? It used to be simple - selecting rows from the referral table and gluing (JOIN) with the registration table. With this approach, there are several bugs: On days when there were no clicks on the link, statistics are not displayed, if there are more than 1 registrations, then the number of uniques (clicks on the link) is multiplied by the number of regs (the COUNT (DISTINCT id) methods were solved, but in my opinion - it's a crutch!).
How to implement the correct calculation of statistics by day in MySQL?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Bezymyannikov, 2016-07-11
@synapse_people

From date and partner_id, make a composite key like 13-2015-07-04 for example. Make it unique.
When writing, insert 1 into the value or update +1.
When displaying a chart, initially fill with zeros all dates that are empty (at least create an array by period filled with zeros and pour an array from the database into it).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question