Good afternoon, colleagues! Your opinion is required regarding the logic of building statistics online store using Google charts. Google Charts was chosen for its simplicity and gratuity.

I apologize in advance in SQL and the backend is not strong. With the construction of logic, too, I do not have much experience.

What we have:

  1. Mysql database;

  2. 5 tables where the clicks are recorded (1 - old customer, 2 - new customer, 3 - product, 4 - comments, 5 - reviews);

What is necessary:

Task number 1. build 5 graphs of the results of clicks recorded in each table;

Task number 2. build on the basis of the values ​​of 5 tables - 1 schedule of clicks throughout the store.

The author's vision of the question:

Solution of the problem №1 - since the GC chart takes ready-made values ​​of the table fields, first summarize the value of each row of the table and write their result into a separately created table, let's call it total-1 - thereby solving the problem with the output of 5 tables charts.

Solution of the problem №2 - then I summarize the results of 5 tables and write down the total-2 table created in the second one, thus constructing a graph throughout the store.

As a result, two new tables. Will this be an optimally and correctly constructed data collection scheme and output them?

    1 answer 1

    I'm not sure that I understood the question correctly, but do you need to store the calculation of plotting in a table in your project? If there is no such need, then what did the union not please?

    SELECT <нужные поля из таблицы раз> FROM <таблица раз> WHERE <условия на таблицу раз> UNION ALL SELECT <нужные поля из таблицы два> FROM <таблица два> WHERE <условия на таблицу два> UNION ALL SELECT ... 

    The limitation, of course, is that the set of fields in the subqueries should be the same, but if it was planned to be stored in one table, then it is already the same. Similarly for the second task. It’s another thing if the tables are huge and cumbersome, and access to this data is often needed quickly, then yes, sometimes, but it makes sense to separate them into a separate table. If you need to count the data once and once a day, for example, update the schedule, then why not just a request.