我有一个更大的SQL查询,我使用Boolean Full-Text Searches
来获取relevance values
。
我得到两个相关值:
两者都分配给aliasses
。现在我想在同一个SQL查询中的新别名(superScore)中为每个匹配添加它们,但似乎sql不能使用别名来计算它。
(scoreTags + scoreContent) AS superScore
我得到了以下错误:
mysqlt error: [1054: Unknown column 'scoreTags' in 'field list']
这是我完整的SQL语句:
SELECT csia.cID, csia.ak_tags, p.cParentID, cv.cvName,
(MATCH (csia.ak_tags) AGAINST ('Bestäubung Bienen Politik' IN BOOLEAN MODE) * 3) AS scoreTags,
MATCH (psi.content) AGAINST ('Bestäubung Bienen Politik' IN BOOLEAN MODE) AS scoreContent,
(scoreTags + scoreContent) AS superScore
FROM CollectionSearchIndexAttributes csia
LEFT JOIN Pages p
ON csia.cID = p.cID
LEFT JOIN CollectionVersions cv
ON csia.cID = cv.cID
LEFT JOIN PageSearchIndex psi
ON csia.cID = psi.cID
WHERE cv.cvIsApproved = 1
AND (MATCH (csia.ak_tags) AGAINST ('Bestäubung Bienen Politik' IN BOOLEAN MODE))
ORDER BY scoreContent DESC, scoreTags DESC, csia.cID DESC
我也尝试了SUM
功能,但它也没有用。你知道如何让它工作吗?谢谢!
我想要的例子:
与cID 9932的查询匹配的相关性值(scoreTags)为5,相关性值为4(scoreContent)。该superScore应为19((5 * 3)+ 4)。
答案 0 :(得分:1)
您可以使用实际函数替换别名,也可以将此语句放入派生表中,然后从中进行聚合。
所以第一个是:
SELECT csia.cID,
csia.ak_tags,
p.cParentID, cv.cvName,
(MATCH (csia.ak_tags)
AGAINST ('Bestäubung Bienen Politik'
IN BOOLEAN MODE) * 3) AS scoreTags,
MATCH (psi.content)
AGAINST ('Bestäubung Bienen Politik'
IN BOOLEAN MODE) AS scoreContent,
(MATCH (csia.ak_tags)
AGAINST ('Bestäubung Bienen Politik' IN BOOLEAN MODE) * 3)
+
MATCH (psi.content)
AGAINST ('Bestäubung Bienen Politik' IN BOOLEAN MODE) AS SUperScore
FROM CollectionSearchIndexAttributes csia
LEFT JOIN Pages p
ON csia.cID = p.cID
LEFT JOIN CollectionVersions cv
ON csia.cID = cv.cID
LEFT JOIN PageSearchIndex psi
ON csia.cID = psi.cID
WHERE cv.cvIsApproved = 1
AND (MATCH (csia.ak_tags) AGAINST ('Bestäubung Bienen Politik' IN BOOLEAN MODE))
ORDER BY scoreContent DESC, scoreTags DESC, csia.cID DESC
或者第二个:
select cID,
ak_tags,
cParentID,
cvName,
scoreTags,
scoreContent,
scoreTags+ScoreContent as SuperScore from (
SELECT csia.cID, csia.ak_tags, p.cParentID, cv.cvName,
(MATCH (csia.ak_tags)
AGAINST ('Bestäubung Bienen Politik'
IN BOOLEAN MODE) * 3) AS scoreTags,
MATCH (psi.content)
AGAINST ('Bestäubung Bienen Politik'
IN BOOLEAN MODE) AS scoreContent
FROM CollectionSearchIndexAttributes csia
LEFT JOIN Pages p
ON csia.cID = p.cID
LEFT JOIN CollectionVersions cv
ON csia.cID = cv.cID
LEFT JOIN PageSearchIndex psi
ON csia.cID = psi.cID
WHERE cv.cvIsApproved = 1
AND (MATCH (csia.ak_tags) AGAINST ('Bestäubung Bienen Politik' IN BOOLEAN MODE))
) x
ORDER BY scoreContent DESC, scoreTags DESC, csia.cID DESC