【发布时间】:2011-02-16 19:20:09
【问题描述】:
这有点超出了我的技能范围,我从 SO 的优秀人员那里得到了很多帮助,才能走到这一步。我现在需要的是放入 MATCH() ... AGAINST() 但我不知道在哪里插入它?
我的查询是(这是简短的版本):
SELECT
SQL_CALC_FOUND_ROWS i.idItems RowCount,
i.* Items,
# Create a JSON formatted field
CONCAT('{',GROUP_CONCAT('"',Attributes.key, '":"', CONVERT(Attributes.value,CHAR),'"'),'}') as Attributes,
IF (te.Key IS NULL,tp.Key,te.Key) as Type,
tc.Value Color,
l.* Location,
c.Name,
c.Mobile,
c.Mail
FROM
(SELECT ItemID, ats.Key, ats.Value FROM attributeStrings as ats
UNION ALL
SELECT ItemID, ati.Key, ati.Value FROM attributeIntegers as ati
) Attributes
JOIN Items i ON
i.idItems = Attributes.ItemID
AND CheckIn >= DATE_SUB('2011-02-16 00:00:00',INTERVAL 90 DAY)
AND CheckIn <= DATE_ADD('2011-02-16 23:59:59',INTERVAL 90 DAY)
AND Checkout IS NULL
LEFT JOIN Customers c ON c.idCustomers = i.CustomerID
LEFT JOIN attributeintegers atli ON atli.itemid = i.idItems AND atli.key = 'Location'
LEFT JOIN locations l ON l.id = atli.value
LEFT JOIN attributestrings atts ON atts.itemid = i.idItems AND atts.key = 'Type' LEFT
JOIN Lists tp ON tp.value = atts.value
LEFT JOIN attributestrings attes ON attes.itemid = i.idItems AND attes.key = 'Tech' LEFT
JOIN Lists te ON te.value = attes.value
LEFT JOIN attributeintegers atci ON atci.itemid = i.idItems AND atci.key = 'Color' LEFT
JOIN Strings tc ON tc.StringID = atci.value
GROUP BY Attributes.ItemID
ORDER BY CheckIn DESC
现在我需要把这个声明放在这里的某个地方
MATCH(attributestrings.Value) AGAINST("Nokia" IN BOOLEAN MODE)
如您所见,有一个名为 attributestrings 的表,它有 3 列:ItemID、*Key* 和 Value。我需要在 Value 列中搜索 AGAINST() 中的单词,并且只显示匹配此条件和其他条件(例如上面的日期和结帐)的结果。
我尝试在AND Checkout IS NULL 之后添加语句,如下所示:
AND Checkout IS NULL
AND MATCH(Attributes.Value) AGAINST("Nokia" IN BOOLEAN MODE)
我不得不使用 Attributes.Value 而不是 attributestrings 因为它没有找到表。这只会导致 CONCATENATE 列 Attributes 仅包含值“Nokia”,即使还有更多要 CONCATENATE 的地方。
我希望有人愿意接受这个挑战......
// 坦克你。
[编辑]
按照 Tim Fultz 的建议,我尝试在 GROUP 之前输入 WHERE,但出现错误 “Where 子句”中的未知列“attributestrings.Value”
LEFT JOIN attributeintegers atci ON atci.itemid = i.idItems AND atci.key = 'Color' LEFT JOIN Strings tc ON tc.StringID = atci.value
WHERE MATCH(attributestrings.Value) AGAINST("Nokia Sony" IN BOOLEAN MODE)
GROUP BY Attributes.ItemID
【问题讨论】: