无法从 select 语句插入日期错误代码:1292 MySQL

Trouble inserting date from select statement Error Code: 1292 MySQL

我正在协调两个不同的数据源。我正在尝试根据一系列条件从其中一个插入另一个,使用像这样的语句

INSERT INTO `tab`.`listsalesorders`
(`number`,
`name`,
`status`,
`parentProjectID`,
`dateEntered`,
`individualId`,
`taxable`,
....
SELECT 
m.number as `number`, 
m.name as `name`, 
3 as `Status`,
-1 as `individualId`,
m.parentProjectID as `parentProjectID`,
m.dateEntered as `dateEntered`, 
m.taxable as `taxable`, 
...
FROM (SELECT si.number as `number`, 
si.description as `name`, 
si.date as `dateEntered`,
p.idx as `parentProjectID`, 
si.date as `Date`, 
IF(si.salesTaxID='NJ',2,1) as `taxable` FROM listsoli si 
JOIN listprojects p ON LEFT(si.number,LOCATE('-',si.number) - 1)=p.number
GROUP BY si.number) as m;

我得到 Error Code: 1292. Incorrect datetime value: '498' for column 'dateEntered' at row 1

我在另一个选项卡中查看了我的 SELECT 报表数据,添加了 HAVING dateEntered LIKE '%498%' 以及 HAVING dateEntered IS NULLHAVING dateEntered = '' 因为我已经阅读了这两个可能会导致问题,但不会出现一行。只是查看数据并按 dateEntered 排序,我发现两端都没有问题。

是什么原因造成的,我该如何修复或解决它?

对于 INSERT ... SELECT 语句,列名(或别名)无关紧要。 INSERT 和 SELECT 中列的顺序必须匹配。示例:

INSERT into test_table (a, b, c)
SELECT
  'c' as c,
  'b' as b,
  'a' as a

相同
INSERT into test_table (a, b, c)
SELECT 'c', 'b', 'a'

INSERT into test_table (a, b, c)
VALUES ('c', 'b', 'a')

在table中你将拥有

a   | b   | c
----|-----|----
'c' | 'b' | 'a'

换句话说:列不是按名称匹配,而是按位置匹配。