我在数据库中有一个JSON字段,它类似于: 【1,2,3,4,5,6,7,8,9,10,11,12】 我试着做一个查询,在那里我可以找到其他两个数组的组合,就像: [1,2,3,4]和[3,4,5,6] 我需要找到两个数组都有值的记录.现在,我正在为数组执行循环内循环,并调用查询,如:
$this->createQueryBuilder('g')
->select('
g.tripId as tripId,
g.routeId as routeId,
g.stops as stops
')
->where("JSON_CONTAINS(g.stops, :firstStopId, '$') = true AND JSON_CONTAINS(g.stops, :lastStopId, '$') = true")
->setParameter('firstStopId', sprintf('"%s"', $firstStopId))
->setParameter('lastStopId', sprintf('"%s"', $lastStopId))
->getQuery()
->getArrayResult()
有什么办法可以优化这一点吗?也许有一种方法可以搜索Json字段是否有任何数组的值?