我有一个选择多个列表的html控件,它使最终用户能够选择多个项目。目前,我将用户选择的值作为"truck,heavy truck,others“存储到mysql varchar字段中。但如果用户在选择多个控件上选择卡车,则卡车和重型卡车都会被搜索到。此查询的SQL语句类似于"select truck table where trackType like '%truck%'“。
似乎解决方案的唯一方法是将选定的值放入另一个表中。
有没有其他方法可以在一个表中处理这个问题?
发布于 2014-05-19 15:03:59
将,添加到结尾处并同时开始
因此,值变成了, truck, heavy truck, others,
使用此查询
select truckType from table where trackType like '%, truck,%注意:like '%, truck,%'中的,
发布于 2014-05-19 15:10:07
你应该做一个单独的表格:
------------------
typeId | type |
-----------------
1 | truck |
2 | heavy truck |
....另请参阅实体表:
------------------
entityid | |
-----------------
1 | entity1 |
2 | entity2 |和其他表将与此表具有多对一关系:
-------------------------------
id | typeId | entityId |
-------------------------------
1 | 1 | 2 |
2 | 2 | 2 |
2 | 2 | 1 |您的select将是这两个表的连接。
https://stackoverflow.com/questions/23731512
复制相似问题