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