SELECT foto.id, COUNT(g1.kol), COUNT(g2.kol) FROM foto LEFT JOIN golos AS g1 ON foto.id=g1.foto_id LEFT JOIN golos AS g2 ON foto.id=g2.foto_id AND g2.time BETWEEN $t1 AND NOW()