日期:2014-05-16  浏览次数:20714 次

求一sql语句,感觉有点麻烦
最近使用cms,升级后麻烦真多,下面为2张表图片


我想把图1里面的"catid"字段复制到图2里面的"catid"里面
但必须图1里面的"id"和图2里面的"hitsid"中的c-1-1一样(红色部分),不然catid就导入错误了
求sql高手。。。。。

------解决方案--------------------
try
SQL code
update cc_hits,cc_news set cc_hits.catid=cc_news.catid where cc_hits.hitsid = concat('c-1-',cc_news.id);

------解决方案--------------------
update cc_hits a inner join cc_news b 
on b.id=right(a.hitsid,1) set a.catid=b.catid
------解决方案--------------------
楼上强大~ 建议将right改成substring_index
SQL code

update cc_hits a inner join cc_news b
on b.id=substring_index(a.hitsid,'-',-1) set a.catid=b.catid