我有'record'表,其中包含两列“meta_value”和“field_id”:
meta_value field_id item_id
Customer 11 1
Sweden 1 1
Second 1 1
First 1 1
Done 1 2
No 1 2
First1 2 2
First2 2 2
Finland 2 3
Customer 11 3
112233 2 3
Booked 2 3
First NAme 89 4
Last Name 9 4
Belgium 3 4
Customer Name 11 4
11223344 12 5
Booked 3 5
First Name2 89 5
Last Name2 9 5
The Netherlands 10 6
Customer Name2 11 6
221133 4 6
Booked 4 6
Item_id
表示在网站上提交的表单的ID,
field_id
- 表格中的参数名称
和meta_value
- 此参数的值。
field_id=1
是此人的姓名(值存储在meta_value
中),field_id=2
是关键字(值存储在meta_value
中),此人有输入
我需要做的是展示排名前5位的人,他们作为关键词最多次进入“预订” 我在MySQL请求方面不是很好,所以也许有人可以帮助我?
答案 0 :(得分:0)
我做到了:
SELECT t3.name, COUNT(*) as Cnt FROM
(SELECT t1.meta_value AS name, t2.meta_value AS type, t2.item_id AS field_id FROM
( SELECT * FROM wp_frm_item_metas WHERE field_id=9) AS t1 INNER JOIN ( SELECT * FROM wp_frm_item_metas WHERE field_id=13) AS t2 ON t1.item_id = t2.item_id WHERE t2.meta_value="Booked") AS t3 GROUP BY t3.name ORDER BY Cnt DESC