在内连接条件语句中连接字符串中的变量

时间:2017-06-13 12:06:19

标签: mysql

我想在内连接条件语句中搜索数据库中字符串中的变量。我想在wp_idpl_orders.product_id的{​​{1}}中使用%替换ign_product_level_%_price。我怎么能这样做?

SELECT * FROM `wp_idpl_orders` INNER JOIN wp_postmeta WHERE wp_postmeta.meta_key like "ign_product_level_%_price" and wp_postmeta.meta_key like wp_idpl_orders.product_id and wp_postmeta.post_id = wp_idpl_orders.post_id

1 个答案:

答案 0 :(得分:0)

MySQL CONCAT()函数用于添加两个或更多字符串。

SELECT * FROM `wp_idpl_orders` INNER JOIN wp_postmeta WHERE wp_postmeta.meta_key like concat("ign_product_level_",wp_idpl_orders.product_id,"_price") and wp_postmeta.post_id = wp_idpl_orders.post_id