请问大家,工作上有个project需要,5K的 records, 将它们的一个值修改。update table name set column1='codeA' +'codeB' where column1 is null;其中codeA是primary key(有5K的变量值), codeB是不变的常值。请问怎样写这个command,可以批处理所有的5K数据,每一条出来的值都是它所对应的primary key加上不变的值的combination,而不需要一条条每一个primary key写一个命令。很感谢!我的SQL还不精通,特来请教,向大家虚心学习。
请问大家,工作上有个project需要,5K的 records, 将它们的一个值修改。update table name set column1=''codeA'' +''codeB'' where column1 is null;其中codeA是primary key(有5K的变量值), codeB是不变的常值。请问怎样写这个command,可以批处理所有的5K数据,每一条出来的值都是它所对应的primary key加上不变的值的combination,而不需要一条条每一个primary key写一个命令。很感谢!我的SQL还不精通,特来请教,向大家虚心学习。
感谢二楼和上面最后一楼的姐妹!我早上赶着要出门,没有把要问的说清楚,抱歉。下面是我重新修改过的,再次来请教大家。 set新值给column A为总共几千条数据,每一条数据的column A新值是combine固定值ZZZ +那条数据的primary key. 如果按下面的写法,得逐条record写一个SET命令(因为primary key不同)。想请教的是,怎么改写下面的命令,可以用一条set的命令,或更简洁的命令,同时为几千条数据定新column A的值。非常感谢!! update table X set column A ='ZZZ_111' where column A is null and primary_key ='111'; set column A ='ZZZ_222' where column A is null and primary_key ='222'; set column A ='ZZZ_333' where column A is null and primary_key ='333'; --ZZZ is a fixed value. --111, 222, 333 and so on。。。are the primary keys associated with each row of values.
something like update tableA set columnA = (select primaryKey from tableA ) || ' ' || constantValeStr where columnA is null check the systax from your db vendor
codeA用列名,别加引号啊。对自己的命令不确定的时候先用select试一下
update table X set column A ='ZZZ_111' where column A is null and primary_key ='111'; set column A ='ZZZ_222' where column A is null and primary_key ='222'; set column A ='ZZZ_333' where column A is null and primary_key ='333'; --ZZZ is a fixed value. --111, 222, 333 and so on。。。are the primary keys associated with each row of values.
👍加一条back up the entire database.