CREATE VIEW desks_data_count AS
SELECT
    desks.desk_id AS desk_id,
    ifnull(desks_cards.countCards, 0) AS cards,
    ifnull(desks_desks.countDesks, 0) AS desks
FROM
    desks
    LEFT JOIN (
        -- cards
        SELECT
            desks.desk_id AS desk_id,
            COUNT(cards_data_base.card_id) AS countCards
        FROM
            desks
            JOIN cards_data_base on desks.user_id = cards_data_base.user_id
        WHERE
            cards_data_base.tree LIKE CONCAT('%', desks.desk_id, '%')
        GROUP BY
            desks.desk_id
    ) desks_cards ON desks.desk_id = desks_cards.desk_id
    LEFT JOIN (
        -- desks
        SELECT
            desks.parent_desk AS desk_id,
            COUNT(desks.desk_id) AS countDesks
        FROM
            desks
        GROUP BY
            desks.parent_desk
    ) desks_desks ON desks.desk_id = desks_desks.desk_id
    