我使用以下查询获取数据
SELECT t1.user_id, t1.time_spent , t1.goal FROM
(SELECT temp_user_notes.user_id as user_id, temp_user_notes.activity_goal as goal, user_activities.activity_date as dates,
date(now()) as activity_date, sum(user_activities.time_spent) as time_spent
FROM temp_user_notes
INNER JOIN user_activities
ON temp_user_notes.user_id = user_activities.user_id
WHERE activity_date = date(now())
group by user_id, goal, dates,activity_date) as t1
WHERE time_spent > goal ;
并且它给出了这个结果
user_id time_spent goal
136 3000 0
135 2000 5
但如果我试图将此结果保存在其他表user_records中,那么它会给我Truncated incorrect datetime value: ''
错误。即使我没有插入日期时间字段
insert into user_records
(user_id,
goal,
time_spent)
(SELECT
t3.user_id,
t3.goal,
t3.time_spent
FROM
(SELECT t1.user_id, t1.time_spent , t1.goal,t1.activity_date FROM
(SELECT temp_user_notes.user_id as user_id, temp_user_notes.activity_goal as goal, user_activities.activity_date as dates,
date(now()) as activity_date, sum(user_activities.time_spent) as time_spent
FROM temp_user_notes
INNER JOIN user_activities
ON temp_user_notes.user_id = user_activities.user_id
WHERE activity_date = date(now())
group by user_id, goal, dates,activity_date) as t1
WHERE time_spent > goal);
愚蠢的是,如果我试图通过user_table插入值,我没有任何日期约束错误。
insert user_records (user_id,goal,time_spent)
select id , activity_goal as goal, login_count as time_spent
from users limit 1;