mysql - Select rows grouped by keyword but weight each group instead of using COUNT() -
I use the MySQL database server and I have a table named keywords with the following structure Is:
Kevard_name | Product_id as well as a list of keywords. I can sort the keyword table based on the list with the following questions:
SELECT *, COUNT (*) with keyword WHERE keyword_name IN (comma separated List of keywords) Product_id Hosting Group (*) & gt; Order by 2 (*) DESC Is there a way to add weight to keywords, that is, some words that increase COUNT (*) with more than one? Using the
this ,
is , this . If you want the keyword this and that to load the weight of 3, this 2, and something else 1, then you You can do this: SELECT keyword_name, SUM (case when keyword_name IN ('this', 'that') then 3 when keyword_name IN ('this') then weighs 2 or 1 nd) Keyword_name from MyTable group; This is an example.
To match the design of your query, you must first add by adding your order and sequence:
SELECT keyword_name, SUM (case when keyword_name IN ('This', 'that') 3 when keyword_name IN ('these') THEN 2 ELSE 1 END) weight and weight by keyword_name from myTable GROUP; Order according to 2 DESC weight;
Comments
Post a Comment