mysql вставить в не работает, но выберите делает - PullRequest
1 голос
/ 23 января 2020

Работает следующий sql код:

SELECT 
        T1.id, 
        IF(hours_per_week IS NULL OR hours_per_week = '', 0, 3) as hours_per_week,
        IF(T2.rate_per_hour IS NULL OR T2.rate_per_hour = '', 0, 3) as rate_per_hour,
        IF(T2.available_for IS NULL OR T2.available_for = '', 0, 4) as available_for,
        IF(T3.user_id IS NULL OR T3.user_id = '', 0, 10) as user_education,
        IF(T4.user_id IS NULL OR T4.user_id = '', 0, 10) as user_expertises,
        IF(T5.user_id IS NULL OR T5.user_id = '', 0, 5) as user_hobbies,
        IF(T6.hacker_test_id IS NULL OR T6.hacker_test_id = '', 0, 15) as user_hacker_test,
        IF(T7.user_id IS NULL OR T7.user_id = '', 0, 5) as user_languages,
        IF(T8.user_id IS NULL OR T8.user_id = '', 0, 5) as user_portfolios,
        IF(T9.user_id IS NULL OR T9.user_id = '', 0, 10) as user_work_experience,
        IF(T1.profile_picture IS NULL OR T1.profile_picture = '', 0, 10) as profile_picture,
        IF(T2.about IS NULL OR T2.about = '', 0, 10) as about,
        IF(T2.location IS NULL OR T2.location = '', 0, 5) as location,
        IF(T1.type IS NULL OR T1.type = '', 0, 5) as type
    FROM 
        users T1
    LEFT JOIN 
        user_details T2
    ON
        T1.id = T2.user_id
    LEFT JOIN 
        user_education T3   
    ON
            T1.id = T3.user_id
    LEFT JOIN 
        user_expertises T4   
    ON
            T1.id = T4.user_id
    LEFT JOIN 
        user_hobbies T5   
    ON
            T1.id = T5.user_id
    LEFT JOIN 
        user_hacker_test T6   
    ON
            T1.id = T6.user_id
    LEFT JOIN 
        user_languages T7   
    ON
            T1.id = T7.user_id
    LEFT JOIN 
        user_portfolios T8   
    ON
            T1.id = T8.user_id
    LEFT JOIN 
        user_work_experience T9   
    ON
            T1.id = T9.user_id
    GROUP BY
        T1.id,
        hours_per_week,
        rate_per_hour,
        available_for,
        user_education,
        user_expertises,
        user_hobbies,
        user_hacker_test,
        user_languages,
        user_portfolios,
        user_work_experience,
        profile_picture,
        about,
        location,
        type;

, выдающий следующий результат:

enter image description here

, но если я попытаюсь чтобы вставить результаты в существующую таблицу, используя этот код:

INSERT INTO user_profile_completion (
    id,
    hours_per_week,
    rate_per_hour,
    available_for,
    user_education,
    user_expertises,
    user_hobbies,
    user_hacker_test,
    user_languages,
    user_portfolios,
    user_work_experience,
    profile_picture,
    about,
    location,
    type
)
    SELECT 
        T1.id, 
        IF(hours_per_week IS NULL OR hours_per_week = '', 0, 3) as hours_per_week,
        IF(T2.rate_per_hour IS NULL OR T2.rate_per_hour = '', 0, 3) as rate_per_hour,
        IF(T2.available_for IS NULL OR T2.available_for = '', 0, 4) as available_for,
        IF(T3.user_id IS NULL OR T3.user_id = '', 0, 10) as user_education,
        IF(T4.user_id IS NULL OR T4.user_id = '', 0, 10) as user_expertises,
        IF(T5.user_id IS NULL OR T5.user_id = '', 0, 5) as user_hobbies,
        IF(T6.hacker_test_id IS NULL OR T6.hacker_test_id = '', 0, 15) as user_hacker_test,
        IF(T7.user_id IS NULL OR T7.user_id = '', 0, 5) as user_languages,
        IF(T8.user_id IS NULL OR T8.user_id = '', 0, 5) as user_portfolios,
        IF(T9.user_id IS NULL OR T9.user_id = '', 0, 10) as user_work_experience,
        IF(T1.profile_picture IS NULL OR T1.profile_picture = '', 0, 10) as profile_picture,
        IF(T2.about IS NULL OR T2.about = '', 0, 10) as about,
        IF(T2.location IS NULL OR T2.location = '', 0, 5) as location,
        IF(T1.type IS NULL OR T1.type = '', 0, 5) as type
    FROM 
        users T1
    LEFT JOIN 
        user_details T2
    ON
        T1.id = T2.user_id
    LEFT JOIN 
        user_education T3   
    ON
            T1.id = T3.user_id
    LEFT JOIN 
        user_expertises T4   
    ON
            T1.id = T4.user_id
    LEFT JOIN 
        user_hobbies T5   
    ON
            T1.id = T5.user_id
    LEFT JOIN 
        user_hacker_test T6   
    ON
            T1.id = T6.user_id
    LEFT JOIN 
        user_languages T7   
    ON
            T1.id = T7.user_id
    LEFT JOIN 
        user_portfolios T8   
    ON
            T1.id = T8.user_id
    LEFT JOIN 
        user_work_experience T9   
    ON
            T1.id = T9.user_id
    GROUP BY
        T1.id,
        hours_per_week,
        rate_per_hour,
        available_for,
        user_education,
        user_expertises,
        user_hobbies,
        user_hacker_test,
        user_languages,
        user_portfolios,
        user_work_experience,
        profile_picture,
        about,
        location,
        type;

Я получаю следующую ошибку:

enter image description here

Это в таблицу, куда я хочу вставить значения:

enter image description here

Что не так с моим оператором вставки?

...