duancai7002 2017-03-12 17:35
浏览 66

SQL查询:获取具有最大编号的字符串| 解析?

I have a database which looks like this: enter image description here

Do not ask my why, but this is written by a WordPress plugin so I have to handle with it. What I want is to get every link where the meta_key = product_shops_X_link. But every post has a variable amount of product shop links.

In this picture I tried Where meta_key Like "%_link%". But if I do a query like that I also get all meta_keys where the product_shops_X_link field has a _ before the product...

What I want is just all product_shops_X_link fields. Now there a two ways I think.

Way 1: Get the highest number of the meta key fields Where meta_key Like "%product_shops_X_link%" OR meta_key Like "%_product_shops_X_link%". It doesn't matter of _product or just product. The numbers are equal. If there is just a product_shops_0_link field there must be also a _product_shops_0_link field.

Way2: Create a pattern which only searches for all product_shops_X_link fields without the beginning of _product and give me ALL product_shops_X_link fields. Whatever number is contained in the field.

But in both cases I do not know how to code that.. Does anyone knows how to code that or is there maybe a better way?

Greetings and Thank You!

  • 写回答

3条回答 默认 最新

  • donglankui1263 2017-03-12 17:40
    关注

    If you don't want entries starting with _product then you can exclude _ or % from your LIKE pattern, e.g.:

    SELECT *
    FROM links
    WHERE meta_key LIKE 'product_%';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私