'games per day count' AS `title`,
truncate(avg(`P1`.`games`), 0) AS `average`,
min(`P1`.`games`) AS `min`,
max(`P1`.`games`) AS `max`
FROM
(
SELECT
`table1`.`dateval` AS `dateval`,
`table1`.`moves` AS `moves`,
`table2`.`games` AS `games`
FROM
(
(
SELECT
count(`M`.`id`) AS `moves`,
CAST(`M`.`created_at` AS date) AS `dateval`
FROM
`chess`.`moves` `M`
GROUP BY
`dateval`
) `table1`
JOIN (
SELECT
count(`G`.`id`) AS `games`,
CAST(`G`.`created_at` AS date) AS `dateval`
FROM
`chess`.`games` `G`
GROUP BY
`dateval`
) `table2` ON
(
(
`table1`.`dateval` = `table2`.`dateval`
)
)
)
) `P1`
WHERE
(
(
CAST(`P1`.`dateval` AS date) <> CAST((now() + INTERVAL 3 HOUR) AS date)
)
AND (
(
`P1`.`dateval` < '2020-12-29'
)
OR (
`P1`.`dateval` > '2021-01-12'
)
)
)
GROUP BY
`title`
UNION
SELECT
'moves per day count' AS `title`,
truncate(avg(`P2`.`moves`), 0) AS `average`,
min(`P2`.`moves`) AS `min`,
max(`P2`.`moves`) AS `max`
FROM
(
SELECT
`table1`.`dateval` AS `dateval`,
`table1`.`moves` AS `moves`,
`table2`.`games` AS `games`
FROM
(
(
SELECT
count(`M`.`id`) AS `moves`,
CAST(`M`.`created_at` AS date) AS `dateval`
FROM
`chess`.`moves` `M`
GROUP BY
`dateval`
) `table1`
JOIN (
SELECT
count(`G`.`id`) AS `games`,
CAST(`G`.`created_at` AS date) AS `dateval`
FROM
`chess`.`games` `G`
GROUP BY
`dateval`
) `table2` ON
(
(
`table1`.`dateval` = `table2`.`dateval`
)
)
)
) `P2`
WHERE
(
(
CAST(`P2`.`dateval` AS date) <> CAST((now() + INTERVAL 3 HOUR) AS date)
)
AND (
(
`P2`.`dateval` < '2020-12-29'
)
OR (
`P2`.`dateval` > '2021-01-12'
)
)
)
GROUP BY
`title`
Обсуждают сегодня