Yii2 anFilterWhere 带逗号字符串

Yii2 anFilterWhere with comma string

假设我在 table 中有这样的数据

ID     student_name     score
1      ABC              1,3
2      DEF              11,2
3      GHI              5,2,13

score : 是字符串

这是我试过的

$query->andFilterWhere(['like', 'score', $this->score]);

我想做的是当我通过 "score" 搜索“1”时它应该 return 只有第一条记录,但它 return 所有记录。 当我搜索“2”时,它应该 return 2 rows(2 & 3)

请帮忙!!!

  1. 更改您的逻辑,以便在保存分数时保存为 ,1,3, (注意首末逗号)

  2. 更新以逗号结尾的分数字段 所以更新查询看起来像 更新 table set score = concat(',', score, ',')

  3. $query->andFilterWhere(['like', 'score', ',' . $this->score . ',']);