Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.3k views
in Technique[技术] by (71.8m points)

mysql 有间隔符的字符串查询的问题

image
如图,想要查询字段 type_sid 中带有 gys 的所有记录
要怎么写的优雅,查询的准确。
还有是不是这种设计不太合理?要使用主从表更好 ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

SELECT * FROM contact_company WHERE FIND_IN_SET('gys',type_sid);

这样用不上索引啊..

如果你这个类型比较少,就在这个表里,每个类型一个标志位来记录.
如果你的这个类型比较多的话,还是加个类型表和一个中间多对多的关系表来处理.

又或者存储 bit 类型,每个 bit 位代表一个类型,然后用位计算来判断.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...