【发布时间】:2016-05-05 09:36:27
【问题描述】:
我有一个包含 3 列的表格
id | name | description
------------------------------------------
1 | Service marketing | Description for the marketing
2 | Marketing | Service marketing
3 | Great customer Service | Helpful shows your customers that you really do care about them.
我想从列名、描述中搜索基于“服务”的值,并且我需要按名称和描述按 asc 顺序对值进行排序。我期望结果集如下。
id | name | description
------------------------------------------
1 | Service marketing | Description for the marketing
3 | Great customer Service | Helpful shows your customers that you really do care about them.
2 | Marketing | Service marketing
我尝试了以下查询,但不起作用
SELECT * FROM search where `name` LIKE '%service%'
OR `description` LIKE '%service%'
ORDER BY name,description;
上述查询的结果
id | name | description
------------------------------------------
3 |Great customer Service | Helpful shows your customers that you really do c...
2 |Marketing | Service marketing
1 |Service marketing | Description for the marketing
帮我解决这个问题。谢谢
【问题讨论】:
-
你想按照word service在两列中的位置排序吗?
-
排序标准是什么?从您的示例看来,您需要先按“描述”排序,然后按“名称”排序,但我不确定这是否是您想要的
-
我正在使用 LIKE 搜索基于服务的值。在名称列 ID 1,3 中包含价值服务,所以首先我需要在描述后按名称排序