我有一张桌子,上面放着一些产品。表格中有一些名为image1,image2,...,image25的字段,这些字段显然可以保存产品图片。
不幸的是,通过界面用数据填充表格的人在图像字段中留下了一些“漏洞”。意味着image1和image2可能都被填充,然后image3可能为空,image4可能被使用,等等...
是否有任何巧妙的查询,例如通过条件更新查询来“压缩”图像,如果3为空则移动4到3,然后5到4,等等?
答案 0 :(得分:0)
无论如何,我只需要一个快速而明智的答案,但是由于我没有想到这样的事情,我最终使用MS Excel自动填充了一些常规的UPDATE语句,如下所示:
UPDATE `prods` SET `image1`=`image2`, `image2`='' WHERE `image1`='';
UPDATE `prods` SET `image2`=`image3`, `image3`='' WHERE `image2`='';
UPDATE `prods` SET `image3`=`image4`, `image4`='' WHERE `image3`='';
UPDATE `prods` SET `image4`=`image5`, `image5`='' WHERE `image4`='';
UPDATE `prods` SET `image5`=`image6`, `image6`='' WHERE `image5`='';
UPDATE `prods` SET `image6`=`image7`, `image7`='' WHERE `image6`='';
UPDATE `prods` SET `image7`=`image8`, `image8`='' WHERE `image7`='';
UPDATE `prods` SET `image8`=`image9`, `image9`='' WHERE `image8`='';
UPDATE `prods` SET `image9`=`image10`, `image10`='' WHERE `image9`='';
UPDATE `prods` SET `image10`=`image11`, `image11`='' WHERE `image10`='';
UPDATE `prods` SET `image11`=`image12`, `image12`='' WHERE `image11`='';
UPDATE `prods` SET `image12`=`image13`, `image13`='' WHERE `image12`='';
UPDATE `prods` SET `image13`=`image14`, `image14`='' WHERE `image13`='';
UPDATE `prods` SET `image14`=`image15`, `image15`='' WHERE `image14`='';
UPDATE `prods` SET `image15`=`image16`, `image16`='' WHERE `image15`='';
UPDATE `prods` SET `image16`=`image17`, `image17`='' WHERE `image16`='';
UPDATE `prods` SET `image17`=`image18`, `image18`='' WHERE `image17`='';
UPDATE `prods` SET `image18`=`image19`, `image19`='' WHERE `image18`='';
UPDATE `prods` SET `image19`=`image20`, `image20`='' WHERE `image19`='';
UPDATE `prods` SET `image20`=`image21`, `image21`='' WHERE `image20`='';
UPDATE `prods` SET `image21`=`image22`, `image22`='' WHERE `image21`='';
UPDATE `prods` SET `image22`=`image23`, `image23`='' WHERE `image22`='';
UPDATE `prods` SET `image23`=`image24`, `image24`='' WHERE `image23`='';
UPDATE `prods` SET `image24`=`image25`, `image25`='' WHERE `image24`='';
我在phpMyAdmin中运行了十几次,直到所有结果消息均受到 0行影响 ...