CREATE VIEW users_data_count AS
SELECT
    users.user_id AS user_id,
    ifnull(users_cards.countCards, 0) AS cards,
    ifnull(users_desks.countDesks, 0) AS desks
FROM
    users
    LEFT JOIN (
        -- cards
        SELECT
            users.user_id AS user_id,
            COUNT(cards_data_base.card_id) AS countCards
        FROM
            users
            JOIN cards_data_base ON cards_data_base.user_id = users.user_id
        GROUP BY
            users.user_id
    ) users_cards ON users.user_id = users_cards.user_id
    LEFT JOIN (
        -- desks
        SELECT
            users.user_id AS user_id,
            COUNT(desks.desk_id) AS countDesks
        FROM
            users
            JOIN desks ON users.user_id = desks.user_id
        GROUP BY
            users.user_id
    ) users_desks ON users.user_id = users_desks.user_id
