AlfieriChou / alfierichou.github.io

AlfieriChou的博客
https://alfierichou.com
4 stars 0 forks source link

MySQL数组查询方案 #16

Open AlfieriChou opened 2 years ago

AlfieriChou commented 2 years ago
  1. 查询数组中包含某个元素

    SELECT id, JSON_SEARCH(`ad`.`statuses`, 'one', "NORMAL") is not null as contain FROM `ad`
  2. 查询数组的长度

    SELECT id, CASE
         WHEN `ad`.`statuses` <> '' THEN
           length(`ad`.`statuses`) - length(replace(`ad`.`statuses`, ',', '')) + 1
         ELSE
           0
       END as arrayLength
       FROM `ad`