0

询问:

    SELECT
        c,

        COUNT
        (   WHEN a='11' AND contains(b,'aa') THEN 1 ELSE NULL END
        ) as total
    from x
group by c

错误:

全文谓词不能出现在聚合表达式中。将聚合表达式放在子查询中。

我正在使用包含,因为它在文本中搜索时使用索引,而且查询也只是这样,所以我只能将它放在聚合表达式中......请建议......

4

2 回答 2

0

试试这个——

SELECT total = COUNT(
    CASE WHEN a = '11' 
          AND CONTAINS(b, 'aa') THEN 1 
    END)
FROM x
于 2013-06-10T06:55:09.150 回答
0

CONTAINS 只能出现在 WHERE 子句中

SELECT
    c,
    COUNT(ContainsResult) AS total
FROM
    (    
    SELECT
        c, CASE WHEN a='11' THEN 1 ELSE NULL END AS ContainsResult
    from
        x
    WHERE
        contains(b,'aa')
    UNION ALL
    SELECT
        c, NULL
    from
        x
    WHERE
        NOT contains(b,'aa')
    ) X1
GROUP BY 
    c
于 2013-06-10T06:56:01.817 回答