0
我的表格名为Products
,因为type
是字段type
值可能是这些值中的任何一个1,2,3,4
。根据字段限制MySQL结果
现在I'would希望得到的结果作为
1. Group the results based on 'type'
2. And Limit the results for each group to 5.
我怎样才能做到这一点,目前我使用下面的查询
SELECT
*,
(
(
CASE
WHEN product_title LIKE '%xyz%'
THEN 2
ELSE 0
END
) + (
CASE
WHEN product_description LIKE '%xyz%'
THEN 1
ELSE 0
END
)
) AS relevance
FROM
Products
WHERE (
(
product_title LIKE '%xyz%'
OR product_description LIKE '%xyz%'
)
)
AND product_available = 1
AND product_deleted <> 1
ORDER BY relevance DESC
其中是样本数据和期望的输出? – 2013-02-09 11:43:54