• MYSQL, PHP как посчитать?

    @mletov
    SELECT user.name,
    	     t1.cnt AS status1,
    	     t2.cnt AS status2,
    	     t3.cnt AS status3
    FROM user
    LEFT JOIN
    (
    	SELECT user_id,
    	       COUNT(status) AS cnt
    	FROM zayavki
    	WHERE status=1
    	GROUP BY user_id
    ) AS t1
    ON user.id = t1.user_id
    LEFT JOIN
    (
    	SELECT user_id,
    	       COUNT(status) AS cnt
    	FROM zayavki
    	WHERE status=2
    	GROUP BY user_id
    ) AS t2
    ON user.id = t2.user_id	
    LEFT JOIN
    (
    	SELECT user_id,
    	       COUNT(status) AS cnt
    	FROM zayavki
    	WHERE status=3
    	GROUP BY user_id
    ) AS t3
    ON user.id = t3.user_id
    Ответ написан
    Комментировать