-1

以下 SELECT 查询工作正常:

select
    StringField_1
    , StringField_2
    , StringField_3
    , COUNT(*)
from my.table
where StringField_1 in (
    select StringField_1
    from my.table
)
group by
    StringField_1
    , StringField_2
    , StringField_3
having
    COUNT(*) > 10
    and StringField_3 like '.*some_string_here.*'
;

结果:

|StringField_1  | StringField_2 | StringField_3 |
|-------------- | ------------- | ------------- |

(0 行受影响)

但是具有上述输出的 UPDATE 失败:

update my.table
set
    StringField_1 = 'CLEAR'
    , numField_1 = 0
where StringField_1 in (
    select
        StringField_1
        , StringField_2
        , StringField_3
        , COUNT(*)
    from my.table
    where StringField_1 in (
        select StringField_1
        from my.table
    )
    group by
        StringField_1
        , StringField_2
        , StringField_3
    having COUNT(*) > 10 and StringField_3 like '.*some_string_here.*'
);

出现以下错误:

ERROR=非法选择列表不能同时包含语句'update my.table set StringField_1 = 'CLEAR', numField= 0 where StringField_1 in (select StringField_1, StringField_12, StringField_13, COUNT(*) from my.table where StringField_1 in (select StringField_1 from my.table) group b...', at or near 'group'

有什么线索吗?

4

3 回答 3

0

您的子查询应该只返回一个列 (StringField_1)

另外,where StringField_1 in (select StringField_1 from my.table)是多余的,你不需要它。

我还将where StringField_3 like '.*some_string_here.*'up 移到 where 子句中,因为这意味着要聚合的行更少,但结果应该是相同的。

update my.table 
set StringField_1 = 'CLEAR', numField_1 = 0 
where StringField_1 in 
(
 select distinct StringField_1
 from my.table 
 where StringField_3 like '.*some_string_here.*'
 group by StringField_1, StringField_2, StringField_3 
 having COUNT(*) > 10 
);
于 2013-07-09T13:58:01.567 回答
0

IN子句只能返回一列:

where StringField_1 in (select StringField_1 
                        from my.table 
                        group by StringField_1, StringField_2, StringField_3 
                        having COUNT(*) > 10 
                            and StringField_3 LIKE '.*some_string_here.*');
于 2013-07-09T13:53:14.823 回答
0

您不能在这样的子查询中返回多个列。此外,无需使用以下内容:

where StringField_1 in (select StringField_1 from my.table) 

尝试这样的事情:

update my.table
set StringField_1 = 'CLEAR', 
    numField_1 = 0
where StringField_1 in (
    select StringField_1
    from my.table 
    group by StringField_1, StringField_2, StringField_3 
    having count(*) > 10 
        and StringField_3 like '.*some_string_here.*'
)
于 2013-07-09T13:55:09.227 回答