2016-11-14 79 views
-3

我已从此查询中删除'age_range'SQL查询INSERT列计数错误

INSERT INTO `filters` (`id`, `user_id`, `profession_preference`, `country`, `city`, `order_by`, `profession_orientation`, `age_range`, `distance_range`, `location_dating`) VALUES 
(9, 20, 3, 'All Countries', '', 2, 1, '16,100', '0,500', 0), 
(10, 12, 3, 'Egypt', '', 2, 1, '', '', 0), 
(11, 19, 3, 'All Countries', '', 2, 1, '16,100', '0,500', 0), 
(13, 20, 3, 'All Countries', '', 2, 1, '16,100', '0,500', 0), 
(14, 20, 3, 'All Countries', '', 2, 1, '16,100', '0,500', 0), 
(15, 20, 3, 'All Countries', '', 2, 1, '16,100', '0,500', 0), 
(25, 121, 3, 'All Countries', '', 3, 1, '18,23', '0,500 ', 0), 
(26, 316, 3, 'United States', '', 3, 1, '17,25', '0,500', 0); 

我再次执行收到此错误:

MySQL said: Documentation

#1136 - Column count doesn't match value count at row 1

+0

你对错误信息的解释是什么? –

+2

您试图将10个值插入9列。 10不匹配9. – David

+0

我已经更新了我的问题,你能帮我确定删除哪个值吗? – agis

回答

1

您的INSERT语句中定义的9列,并且您试图插入10个值。您需要添加另一个列定义或从您的值中删除。

+0

我怎么知道哪一个要删除或哪个是额外的? – agis

+1

@agis:删除不想插入的内容。我们不知道你的价值观是什么。 – David

+0

我已更新我的问题,现在可以查看它吗? – agis

0

由于文件说

"Column count doesn't match value count"

您指定9列(iduser_idprofession_preferencecountrycityorder_byprofession_orientationdistance_rangelocation_dating)在你插入语句 和您要插入10值。

你要删除一个值,或添加另一列

+0

我怎么知道哪一个删除或哪一个是额外的? – agis

+0

我已经更新了我的问题,你能帮我确定我需要删除哪个值吗? – agis

+0

他们匹配,你应该有错误信息 – SamHecquet

1

enter image description here

根据规则列名定义和提供价值数应该是一样的。在你的情况下一个额外的列值。

+0

我已经更新了我的问题,你能帮我确定哪个值要删除? – agis

2

插入记录时,它会按照逗号分隔的位置将VALUES列表中的值与列列表中的列匹配。所以,这个插入语句:

INSERT INTO `foo` (`A`, `B`, `C`) 
VALUES ('valueA', 'valueB', 'valueC') 

它会插入到valueAAvalueB成列B等,因为它们匹配相应的清单位置。如果从列列表中删除B独自离开VALUES,它不会试图插入valueAA列,但valueBC列,因为他们现在的匹配值的位置,但它不会知道,因为有什么用valueC做现在比列更多的值,所以既然您从第二个位置移除了列,您还需要从第二个位置移除该值。

因此,回到您的查询中,您需要确定列列表中占据哪个位置age_range,并从values列表中的相同位置删除值。

这有道理吗?

+0

我认为这是有道理的,但是我会问另外一个问题,以便更清楚我做了什么,我期待什么以及我得到什么错误。 – agis

0

之前列删除这样的脚本,将工作

CREATE TABLE filters (id INT, user_id INT, profession_preference INT, country VARCHAR(50), city VARCHAR(50), order_by INT, profession_orientation INT, age_range VARCHAR(50), distance_range VARCHAR(50), location_dating INT); 

INSERT INTO filters (id, user_id, profession_preference, country, city, order_by, profession_orientation, age_range, distance_range, location_dating) VALUES 
(9, 20, 3, 'All Countries', '', 2, 1, '16,100', '0,500', 0), 
(10, 12, 3, 'Egypt', '', 2, 1, '', '', 0), 
(11, 19, 3, 'All Countries', '', 2, 1, '16,100', '0,500', 0), 
(13, 20, 3, 'All Countries', '', 2, 1, '16,100', '0,500', 0), 
(14, 20, 3, 'All Countries', '', 2, 1, '16,100', '0,500', 0), 
(15, 20, 3, 'All Countries', '', 2, 1, '16,100', '0,500', 0), 
(25, 121, 3, 'All Countries', '', 3, 1, '18,23', '0,500 ', 0), 
(26, 316, 3, 'United States', '', 3, 1, '17,25', '0,500', 0); 

现在,因为你删除AGE_RANGE列,下面的脚本将工作:

INSERT INTO filters (id, user_id, profession_preference, country, city, order_by, profession_orientation, distance_range, location_dating) VALUES 
(9, 20, 3, 'All Countries', '', 2, 1, '0,500', 0), 
(10, 12, 3, 'Egypt', '', 2, 1, '', 0), 
(11, 19, 3, 'All Countries', '', 2, 1, '0,500', 0), 
(13, 20, 3, 'All Countries', '', 2, 1, '0,500', 0), 
(14, 20, 3, 'All Countries', '', 2, 1, '0,500', 0), 
(15, 20, 3, 'All Countries', '', 2, 1, '0,500', 0), 
(25, 121, 3, 'All Countries', '', 3, 1, '0,500', 0), 
(26, 316, 3, 'United States', '', 3, 1, '0,500', 0); 

我从插入脚本文件删除第三的最后一列。

希望这会有所帮助!