Greetings, I just can not properly collect the request into the database.
Here is a screen of the tables and their links: screen of tables and their links
You need to get a mandatory list from the events_global table with such data:

 events_global.id, events_global.name, COUNT(events.id) // это ΠΊΠΎΠ». мСроприятий для ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ элСмСнта ΠΈΠ· events_global, COUNT(tickets.id) // количСство Π±ΠΈΠ»Π΅Ρ‚ΠΎΠ²<br> SUM(tickets.price) // сумма всСх Π±ΠΈΠ»Π΅Ρ‚ΠΎΠ² ΠΏΡ€ΠΈΠ½Π°Π΄Π»Π΅ΠΆΠ°Ρ‰ΠΈΡ… ΠΊΠ°ΠΆΠ΄ΠΎΠΌΡƒ ΠΌΠ΅Ρ€ΠΎΠΏΡ€ΠΈΡΡ‚ΠΈΡŽ ΠΈΠ· events_global 

This is how the table should look like: enter image description here

And here is a link to the online mysql editor with a flooded test database and an underdeveloped curved query

The problem is that in one ticket from the table. tickets can be recorded more than one event in the table. ticket_events and appealing since events_globals passing through ticket_events the same ticket is affected several times and breaks all counts.
I would be very grateful to everyone who will help me.
For a long time I have been tormented by this situation.

  • You have all the same glue sequential. Bring ticket_events from the subquery as another table in join and take count(distinct e.id) and count(distinct te.id) - Mike
  • @Mike, that's what prntscr.com/eus82r turns out, each event counted 2 times, although it should be one by one, and the amount should be 400 - Vladislav Siroshtan
  • I began to understand ... your text only says that a ticket gives access to several events, but there is not a word that one ticket can be associated with one event several times. And such a database structure seems at least strange, there is at least something unique in the ticket_events table besides id, why there are two entries with the same event and the same ticket - Mike
  • So, with your current structure, I want to do the simplest "get the price sum of all tickets sold for event number 1" and I can’t do it anymore, because the only ticket is associated with the event several times, apparently instead of join with the ticket_events table, you will have to do join with the subquery select distinct ticket_id, event_id from ticket_events will immediately solve all the problems that were laid at the design stage of the database - Mike

0