Answer the question
In order to leave comments, you need to log in
Array comparison?
Hi all!
There is a table in the database with fields:
id - автоинкремент,
subscriber_id - число (может повторяться),
alive - жива ли запись (может принимать 1 или ноль)
id | subscriber_id | alive
33 | 15 | 0
34 | 15 | 0
$subSessCount = Sessions::find()->where(['subscriber_id'=>$sub->id])->asArray()->all();
$subSessDead = Sessions::find()->where(['subscriber_id'=>$sub->id, 'alive'=>0])->asArray()->all();
if(count($subSessCount) == count($subSessDead)) {
$i++;
}
Answer the question
In order to leave comments, you need to log in
One query
SELECT COUNT(subscriber_id) as subscriber_count, subscriber_id, SUM(alive)
FROM table
GROUP BY subscriber_id
Count how many alive=1 and subtract from subscriber_count
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question