like在mysql子查询中不起作用

gudnpqoy  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(417)

我使用了一些子查询,它根本不工作,如果我给它的工作硬编码id。

SELECT
  (
  SELECT
    COUNT(*)
  FROM
    inventory_set_variations isv
  WHERE
    isv.c_catid LIKE '%[{"id":"c1.catid"}]%' AND isv.company_id = 1
) AS 'count_total_no_of_variations',
`c1`.`catid` AS `catid`

FROM
   category c1
WHERE
  (
    `c1`.`catsid` <> 3 AND c1.company_id = '1'
  )

这不管用,
下面的代码是工作,因为我给硬编码的数据

SELECT
  (
  SELECT
    COUNT(*)
  FROM
    inventory_set_variations isv
  WHERE
    isv.c_catid LIKE '%[{"id":"1000020"}]%' AND isv.company_id = 1
) AS 'count_total_no_of_variations',
`c1`.`catid` AS `catid`

FROM
   category c1
WHERE
  (
    `c1`.`catsid` <> 3 AND c1.company_id = '1'
  )
a1o7rhls

a1o7rhls1#

你可以用 CONCAT 形成 like 条件
改变

LIKE '%[{"id":"c1.catid"}]%'

LIKE CONCAT('%[{"id":"',c1.catid,'"}]%')

相关问题