0

I've been playing around with CONTAINSTABLE for keyword matching in my query. I've been asked to extend what we have so that it ranks on weighting on specific columns. I've a simpler query to show below:

SELECT [KEY], sum(rnk) as weightRank
FROM 
(
    SELECT RANK * 0.05 as rnk, * from CONTAINSTABLE (FundraisingPages, Description,  'marathon') 
    union all 
    SELECT RANK * 1 as rnk, * from CONTAINSTABLE (FundraisingPages, Title,  'marathon') 
) as t
group by [KEY]
order by weightRank desc

This is fine, it returns the [Key] and weightRank as I have asked, but I would also like it to return all of FundraisingPages columns. However, I can't seem to be able to translate that into the SELECT statement.

I have tried both * and FundraisingPages.* but I get the following error message

Column 't.rnk' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

Now I know that I am only selecting rnk from within the FROM part of my query, but any attempt to return more I get the following message

The column 'KEY' was specified multiple times for 't'.

I understand that I'm selecting KEY and what I can only assume is the matching ID in FundraisingPages more than once and that's probably why I'm seeing these errors, but it seems that I can't even select a singular column from that table without getting further errors.

4

1 に答える 1

0

テーブルの列とテーブルの各列を等しくする必要がありJOINました。KEYIDGROUP BY

SELECT SUM(rnk) as weightRank, fp.*
FROM 
(
    SELECT RANK * 0.05 as rnk, [key] from CONTAINSTABLE (FundraisingPages, [Description],  @Keywords) 
    UNION ALL 
    SELECT RANK * 1 as rnk, [key] from CONTAINSTABLE (FundraisingPages, Title,  @Keywords) 
) AS t
JOIN
    FundraisingPages as fp on fp.PageId = [KEY] WHERE STATUS = 'L'
GROUP BY [KEY], fp.PageId, fp.Status, fp.Title, fp.SubTitle, fp.Url, fp.ImageUrl, fp.Description, fp.RecipientName, fp.CharityNumber, fp.FundraiserFirstName, fp.FundraiserLastName, fp.InsertDate, fp.UpdateDate
ORDER BY weightRank DESC
于 2013-10-03T14:16:58.140 に答える