我有两张表:
## search_queries ##
id | user_input | count
1 | "term" | 80
和mad_product_searchindex,其中包含FULLTEXT索引(品牌,短片和关键字)
这是在我们的搜索页面上运行的查询
SELECT *,
MATCH(Brand, ShortDesc, Keywords) AGAINST('$search_term' IN BOOLEAN MODE) AS score
FROM mad_product_searchindex
WHERE MATCH(Brand, ShortDesc, Keywords) AGAINST('$search_term' IN BOOLEAN MODE)
AND DisplayItem = "1" and product_variant_main = "0"
GROUP BY CatalogueRef
ORDER BY score
我想从search_queries生成一个报告,该报告将遍历该表并运行上面的查询并返回匹配为额外列的产品总数。
我已经接近了,但只有当我在$ search_term中硬编码为例如'term'时它才有效,这显然只适用于单行。
SELECT search_queries.user_input AS user_search, count AS searched, count(Results.Totals)
FROM search_queries
LEFT JOIN (
SELECT COUNT(*) AS Totals, 0 AS Bonus,
MATCH(Brand, ShortDesc, Keywords) AGAINST(user_search IN BOOLEAN MODE) AS score
FROM mad_product_searchindex
WHERE MATCH(Brand, ShortDesc, Keywords) AGAINST(user_search IN BOOLEAN MODE)
AND DisplayItem = "1" and product_variant_main = "0"
GROUP BY CatalogueRef
ORDER BY score DESC
) Results ON 0 = Results.Bonus
WHERE 1=1
GROUP BY user_input
我尝试了别名user_search,并输入table.column名称。两者都没有工作,带回一个错误,说它无法找到该列(大概是因为它正在查看mad_product_searchindex。)如何将该列指定为变量? ...或者我用这个完全错误的路线走了?
基本上到
id | user_input | count | returned results
1 | "term" | 80 | 51