Inilah salah satu cara Anda dapat menyelesaikan semuanya dengan kueri berikut:
SELECT
(dividendTable.messages / divisorTable.messages) AS result
FROM
(
SELECT
firstTable.messages,
@rn1 := @rn1 + 1 AS row_number
FROM
(
SELECT
COUNT(channel) AS messages
FROM Chats
WHERE message LIKE '%word%'
GROUP BY UNIX_TIMESTAMP(time) DIV 3600
) FirstTable, (SELECT @rn1 := 0) var1
) AS dividendTable
INNER JOIN
(
SELECT
secondTable.messages,
@rn2 := @rn2 + 1 AS row_number
FROM
(
SELECT
COUNT(channel) AS messages
FROM Chats
GROUP BY UNIX_TIMESTAMP(time) DIV 3600
) secondTable, (SELECT @rn2 := 0) var2
) AS divisorTable
ON dividendTable.row_number = divisorTable.row_number;
Catatan:
Jika Anda ingin hasilnya dibulatkan hingga 2 digit setelah titik desimal, gunakan yang berikut ini sebagai baris pertama kueri:
SELECT
ROUND((dividendTable.messages / divisorTable.messages),2) AS result
Perhatian: Anda belum pernah menggunakan ORDER BY dalam kueri Anda. Anda mungkin mendapatkan perilaku acak.