基于If语句的SQL查询重复记录
我正在尝试编写一个 SQL 查询,该查询将根据另一个表中的字段重复记录。我正在运行 mySQL 5。
(我知道重复记录表明数据库结构很糟糕,但我没有设计数据库,也无法重做这一切 - 这是一个在 wordpress 上运行的 shopp 电子商务数据库。)
每个产品特定属性需要链接到相同的几个图像,因此产品将需要表中每个图像一行 - 数据库实际上并不包含图像,只包含其文件名。 (图像是供客户选择的剪贴画)
基于这些记录...
SELECT * FROM `wp_shopp_spec` WHERE name='Can Be Personalised' and content='Yes'
我想做这样的事情..
对于与该查询匹配的每条记录,从 wp_shopp_asset 复制记录 5134 - 5139 但更改 id,使其成为unique 并将“parent”列中的单元格设置为具有表 wp_shopp_spec 中的“product”值。这意味着为与上述查询匹配的每条记录创建 6 个新记录,所有记录在“parent”中具有相同的值,但具有唯一的 id 和从原始记录复制的所有其他列(即记录 5134-5139)
希望这足够清楚 -非常感谢任何帮助。
I'm trying to write an SQL query that will duplicate records depending on a field in another table. I am running mySQL 5.
(I know duplicating records shows that the database structure is bad, but I did not design the database and am not in a position to redo it all - it's a shopp ecommerce database running on wordpress.)
Each product with a particular attribute needs a link to the same few images, so the product will need a row per image in a table - the database doesn't actually contain the image, just its filename. (the images are of clipart for a customer to select from)
Based on these records...
SELECT * FROM `wp_shopp_spec` WHERE name='Can Be Personalised' and content='Yes'
I want to do something like this..
For each record that matches that query, copy records 5134 - 5139 from wp_shopp_asset but change the id so it's unique and set the cell in column 'parent' to have the value of 'product' from the table wp_shopp_spec. This will mean 6 new records are created for each record matching the above query, all with the same value in 'parent' but with unique ids and every other column copied from the original (ie. records 5134-5139)
Hope that's clear enough - any help greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来您需要交叉连接到您想要的资产值。所以像这样:
It sounds like you need to cross join to the asset values you want. So something like:
对于正在寻找此类信息的人,请注意 shopp_spec 表已不再使用。所有规格(详细信息)都存储在 shopp_meta 表中。
For people who are looking for information like this, know that the shopp_spec table is no longer in use. All specifications (details) are stored in the shopp_meta table.