Здравствуйте. Есть массив
[anatolypower-pamir2] => Array
(
[0] => Array
(
[id] => 64
[to_user] => anatolypower
[from_user] => pamir2
[message] => rrtt
[status] => 1
[send_date] => 2017-09-05 14:07:56
)
[1] => Array
(
[id] => 69
[to_user] => pamir2
[from_user] => anatolypower
[message] => Что такое rrtt ?
[status] => 1
[send_date] => 2017-09-05 14:14:47
)
[2] => Array
(
[id] => 72
[to_user] => anatolypower
[from_user] => pamir2
[message] => Привет :)
[status] => 1
[send_date] => 2017-09-05 18:00:21
)
[3] => Array
(
[id] => 73
[to_user] => pamir2
[from_user] => anatolypower
[message] => Получил твое сообщение
[status] => 1
[send_date] => 2017-09-05 18:00:37
)
)
Как посчитать сколько в нем совпадений где [status] => 1
и [to_user] => pamir2
SELECT m1.*, (SELECT COUNT(*) FROM messages WHERE to_send = m1.to_send) cnt FROM messages m1 LEFT JOIN messages m2 ON m1.to_send = m2.to_send AND m1.id < m2.id WHERE m2.id IS NULL;