insert ignore into user_login_history
(`created_at`,`updated_at`,`created_by`,
`updated_by`,`USER_ID`,`TENANT`,
`LAST_LOGIN`,`deleted`,`published`)
values(
(SELECT
a.created_at,
a.updated_at,
a.created_by,
a.updated_by,
user.id,
a.tenant,
a.created_at,
b'0',
b'1'
FROM
(SELECT audit_log_summary.*
FROM audit_log_summary, (SELECT
user, MAX(created_at) AS created_at, tenant
FROM
audit_log_summary
WHERE
audit_log_summary.REVISION_TYPE = 'LOGGED_IN'
GROUP BY user , TENANT) max_user
WHERE
audit_log_summary.user = max_user.user
AND audit_log_summary.tenant = max_user.tenant
AND audit_log_summary.created_at = max_user.created_at) a
INNER JOIN
user ON a.user = user.email));
我得到的錯誤:
錯誤代碼:1136。列計數與第 1 行的值計數不匹配
基本上我有 3 個表,我想在一個表中填充資料,從其他兩個表中獲取資料。
要填充的表:user_login_history 從中獲取資料的表:audit_log_summary & user
uj5u.com熱心網友回復:
您必須VALUES從子句中洗掉,因此不要使用INSERT INTO VALUES,而是使用INSERT INTO SELECT FROM。也許SELECT audit_log_summary.*您應該只選擇所需的列。在您的選擇中,您選擇了a.created_at兩次,檢查它是否是您想要的。也許這會有所幫助:
insert ignore into user_login_history (`created_at`,
`updated_at`,
`created_by`,
`updated_by`,
`USER_ID`,
`TENANT`,
`LAST_LOGIN`,
`deleted`,
`published`)
(SELECT
a.created_at,
a.updated_at,
a.created_by,
a.updated_by,
user.id,
a.tenant,
a.created_at,
b'0',
b'1'
FROM
(SELECT audit_log_summary.*
FROM audit_log_summary, (SELECT
user, MAX(created_at) AS created_at, tenant
FROM
audit_log_summary
WHERE
audit_log_summary.REVISION_TYPE = 'LOGGED_IN'
GROUP BY user , TENANT) max_user
WHERE
audit_log_summary.user = max_user.user
AND audit_log_summary.tenant = max_user.tenant
AND audit_log_summary.created_at = max_user.created_at) a
INNER JOIN
user ON a.user = user.email));
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/322099.html
