[英]MySQL query the same table with two date fields and group by same ID
[英]Mysql - find fields with same id
我需要根據用戶在文本字段中輸入的關鍵字構造一個查詢,該查詢將執行以下操作:獲取關鍵字並在表中搜索,之后汽車具有所有給定的關鍵字。 我的桌子看起來像這樣:
field_id | car_id | keyword |
----------------------------
1 | 5 | 1989 |
-----------------------------
2 | 8 | old |
-----------------------------
3 | 8 | ford |
-----------------------------
4 | 2 | audi |
-----------------------------
5 | 5 | red |
-----------------------------
6 | 8 | cheap |
-----------------------------
假設用戶搜索了“ old”,“ ford”和“ cheap”,則應返回car_id 8,因為其中包含所有關鍵字。 您將如何實現?
假設您知道輸入的關鍵字數量,並且希望所有關鍵字都匹配。此外,它假定關鍵字car_id是唯一的。 (car_Id 8不能便宜兩次)
Select car_ID from myTable
Where keyword in ('old','ford','cheap')
group by car_ID
having count(*) = 3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.