【问题标题】:mysql select as var and use in an updatemysql select as var 并在更新中使用
【发布时间】:2022-01-31 08:17:53
【问题描述】:

我有一个包含这些字段的数据库:

picture_id  - (varchar) generally the actual filename of the picture (ie. myfile001.jpg)
event - (varchar) string describing the event (ie. Bob's Wedding 2005)
date_of_picture - (varchar) string representing a date (ie. 2004.01.45, Jan 2004, Summer 1969, etc)
filename - (text) - the full path to the picture, including the filename (ie. /pics/bob/2005/wedding)

我现在需要更改一些文件名条目。

有没有一种方法可以查询事件并使用生成的图片 ID 来更新文件名?

类似:

select picture_id as picid from photos where 
   event='Bob's Wedding 2005' update set filename='/my/new/path/here/$picid'

任何给定事件都可能有 100 个图片 ID。

我不是DBA,这只是我个人使用的简单数据库,所以如果我的问题不清楚或者我的数据库结构完全是业余的,请原谅我。

【问题讨论】:

    标签: mysql select sql-update


    【解决方案1】:

    将您的选择翻译成适当的更新,我们可以尝试:

    UPDATE photos
    SET filename = CONCAT('/my/new/path/here/', picture_id)
    WHERE event = 'Bob''s Wedding 2005';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-09
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-27
      相关资源
      最近更新 更多