Tag: 插入

MySQL错误1241:操作数应该包含1列(s)

我正试图从表1插入数据到表2 insert into table2(Name,Subject,student_id,result) select (Name,Subject,student_id,result) from table1; 表2的关键是student_id。 假设没有任何重复。 我得到的错误: MySQL error 1241: Operand should contain 1 column(s) 表2中只有四列。

Python和SQLite:插入到表中

我有一个列有3行,每个代表一个表行: >>> print list [laks,444,M] [kam,445,M] [kam,445,M] 如何将此列表插入表中? 我的表格结构是: tablename(name varchar [100],年龄int,性char [1]) 还是应该使用列表以外的东西? 这里是实际的代码部分: for record in self.server: print "—>",record t=record self.cursor.execute("insert into server(server) values (?)",(t[0],)); self.cursor.execute("insert into server(id) values (?)",(t[1],)) self.cursor.execute("insert into server(status) values (?)",(t[2],)); 插入三个字段分开工作,但使用一个单一的线 self.cursor.execute("insert into server(server,c_id,status) values (?,?,?)",(t[0],),(t[1],),(t[2],)) 要么 self.cursor.execute("insert into server(server,c_id,status) values (?,?,?)",(t),) 才不是。

使用PostgreSQL在数据库之间传输数据

我需要从另一个数据库传输一些数据。 旧的数据库叫做paw1.movi​​esDB,新的数据库是paw1。 每个表的模式如下。 Awards (name of the table)(new DB) Id [PK] Serial Award Nominations (name of the table) (old DB) Id [PK] Serial nominations 如何将旧数据库中的数据复制到新数据库中?

MySQL INSERT INTO … VALUES和SELECT

有没有办法插入从select查询中获得的预设值和值? 例如: INSERT INTO table1 VALUES ("A string", 5, [int]). 我有“一个string”和数字5的值,但我必须从这样的select中find[int]值: SELECT idTable2 FROM table2 WHERE … 这给了我这个ID放在table1里面。 如何合并成一个声明?

如何在SQL表中插入默认值?

我有这样一张桌子: create table1 (field1 int, field2 int default 5557, field3 int default 1337, field4 int default 1337) 我想插入一个具有field2和field4的默认值的行。 我已经尝试insert into table1 values (5,null,10,null)但它不起作用, ISNULL(field2,default)也不起作用。 当我插入一行时,如何告诉数据库使用列的默认值?

如何在MySQL插入语句中包含一个PHPvariables

我试图在内容表中插入值。 它工作正常,如果我没有在VALUES内的PHPvariables。 当我把variables$type VALUES内,那么这是行不通的。 我究竟做错了什么? $type = 'testing'; mysql_query("INSERT INTO contents (type, reporter, description) VALUES($type, 'john', 'whatever')");

MySQL如何插入一个SELECT子查询返回多行的表?

MySQL如何插入一个SELECT子查询返回多行的表? INSERT INTO Results ( People, names, ) VALUES ( ( SELECT d.id FROM Names f JOIN People d ON d.id = f.id ), ( "Henry" ), ); 我想填充新的表格,从这个子查询返回的所有结果。 如何做到这一点,而不会得到错误1242(21000):子查询返回多个行

INSERT INTO与子查询MySQL

我有这个声明: INSERT INTO qa_costpriceslog (item_code, invoice_code, item_costprice) VALUES (1, 2, (SELECT item_costprice FROM qa_items WHERE item_code = 1)); 我试图插入一个值复制相同的数据item_costprice,但显示我的错误: Error Code: 1136. Column count doesn't match value count at row 1 我如何解决这个问题?

使用轨道活动logging上的ruby插入多个logging

有没有办法插入多个logging,而不是一次一个? 我有一个非常非常丑耙的任务是做以下… VoteRecord.create(:prospect_id => prospect.id, :state => "OH", :election_type => "PR", :election => "2000-03-07", :party => row[45], :participate => participated(row[45])) VoteRecord.create(:prospect_id => prospect.id, :state => "OH", :election_type => "GE", :election => "2000-11-07", :party => row[46], :participate => participated(row[46])) VoteRecord.create(:prospect_id => prospect.id, :state => "OH", :election_type => "SP", :election => "2000-05-08", :party => row[47], :participate => […]

追加设置到另一个集合

有没有更好的方法来追加一套到另一套比遍历每个元素? 我有 : set<string> foo ; set<string> bar ; ….. for (set<string>::const_iterator p = foo.begin( );p != foo.end( ); ++p) bar.insert(*p); 有没有更有效的方法来做到这一点?