update select 同一张表 出现问题
表 note
ID content
1 asjdlsdf
2 asda sewaeawe
3 asdasdasd
现在我有先加了一列 Alter table note add summary char(5)
ID content summary
1 asjdlsdf NULL
2 asda sewaeawe NULL
3 asdasdasd NULL
现在我想将 content 里的前五个字符update到summary 里
如:
ID content summary
1 asjdlsdf asjdl
2 asda sewaeawe asda
3 asdasdasd asdas
MySql语句 我是这样写的:
mysql> update note set summary = ( select left(content,10) from (select * from n
ote group by note.id) as x);
结果报错:Subquery returns more than 1 row MySQL
[解决办法]
update note set summary = left(content,5);
基礎問題啊,先靜下心來打好基礎吧。
[解决办法]
update note
set summary=substring(content,1,5)
update note
set summary=STUFF(content,6,LEN(content),'')