CREATE VIEW users_data_import AS
SELECT
    users.user_id AS user_id,
    ifnull(users_CardsImport_open.countCardsImport_open, 0) AS CardsImport_open,
    ifnull(users_DesksImport_open.countDesksImport_open, 0) AS DesksImport_open
FROM
    users
    LEFT JOIN (
        -- Cardsimport_open
        SELECT
            users.user_id AS user_id,
            COUNT(CardsImport_open.card_id) AS countCardsImport_open
        FROM
            users
            JOIN (
                SELECT
                    card_id,
                    user_id
                FROM
                    cards_data_base
                WHERE
                    import_open
            ) CardsImport_open ON CardsImport_open.user_id = users.user_id
        GROUP BY
            users.user_id
    ) users_CardsImport_open ON users.user_id = users_CardsImport_open.user_id
    LEFT JOIN (
        -- DesksImport_open
        SELECT
            users.user_id AS user_id,
            COUNT(DesksImport_open.desk_id) AS countDesksImport_open
        FROM
            users
            JOIN (
                SELECT
                    desk_id,
                    user_id
                FROM
                    desks
                where
                    import_open
                    and parent_desk = 0
            ) DesksImport_open ON users.user_id = DesksImport_open.user_id
        GROUP BY
            users.user_id
    ) users_DesksImport_open ON users.user_id = users_DesksImport_open.user_id