is there any way i can do a query to specify that I want to give priority to some value?
for instance i have:
SELECT TOP (20)
r.MD5, r.Title, r.Link, t.Category, t.tfidf, COUNT(r.MD5) AS matching_terms
FROM
Resource AS r INNER JOIN tags AS t ON r.MD5 = t.MD5
WHERE
(t.Category IN ('algorithm', 'k-means', 'statistics', 'clustering', 'science'))
GROUP BY r.MD5, r.Title, r.Link, t.Category, t.tfidf
ORDER BY matching_terms DESC, t.tfidf DESC
i want that ‘algorithm’ is given higher priority when finding results. any ideas?
I’m not sure how high a priority you want to make
'algorithm', but in any case, you can add this to theORDER BYclause, in order to make it the most important category (all other categories are equally important):If however your concept of “priority” is somehow correlated with the importance of the
matching_termsexpression, you could also try something like this (you’d have to nest your above select)But that’s just an example to give you an idea.
UPDATE: Following you comment, you can generate a case statement like this:
Or alternatively (especially if your list of categories is large), then you should add a
sortfield to tags, containing the priority. Then you could simply order bysort