我已经调用Products
了表,即type
字段type
值可能是这些值中的任何一个1,2,3,4
。
现在我想得到结果
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