簡體   English   中英

Mysql如何選擇字段數組包含此值的行

[英]Mysql how to select row where field's array contains this value

我有這個表結構“帖子”

+----+-------+---------------+
| id | post  | authors_ids   |
+----+-------+---------------+
| 1  | test1 | ["1","2"]     |
+----+-------+---------------+
| 2  | test2 | ["1","3"]     |
+----+-------+---------------+
| 3  | test3 | ["3","4","5"] |
+----+-------+---------------+

我想要做的是選擇在authors_ids字段中包含特定值的行,例如我需要選擇authors_ids 數組包含數字4的帖子

我知道表結構是錯誤的,但此時我將無法更改它。

我怎樣才能做到這一點?

實現此目的的一種快速方法是使用LIKE進行選擇:

SELECT * FROM `posts` WHERE `authors_ids` LIKE '%"4"%';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM