2

I'm using MySql with HeidiSql as an IDE. I have the following trigger:

BEGIN
declare blobpassed blob(50);
declare gid integer(10);
select lt.groupid into gid, GROUP_CONCAT(passed) into blobpassed from latest_tests lt
    left join testcaseresults tcr on tcr.testcaseresultsid = lt.tcrid
    left join grouping g on g.groupid = lt.groupid

    where lt.tcrid = NEW.testcaseresultsid
group by lt.groupid;

if blobpassed REGEXP '[1,]+' THEN 
update grouping g
set g.haspassed = 1
where g.groupid = gid;
END;

But it keeps saying that there is a syntax error around GROUP_CONCAT(passed) into blobpassed from latest_tests lt. Usually, those errors mean that there is something wrong before that (so, in this case, with gid). But i don't see what I'm doing wrong.

Can someone tell me what am I doing wrong? Thanks.

4

1 に答える 1

0

SELECT ... INTOでは、「into」部分は変数リストとともに 1 回だけ書き込まれるため、正しいクエリは次のようになります。

select lt.groupid, GROUP_CONCAT(passed) into gid, blobpassed from latest_tests lt
    left join testcaseresults tcr on tcr.testcaseresultsid = lt.tcrid
    left join grouping g on g.groupid = lt.groupid
    where lt.tcrid = NEW.testcaseresultsid

「into」部分は、クエリの後に配置することもできます。

select lt.groupid, GROUP_CONCAT(passed) from latest_tests lt
    left join testcaseresults tcr on tcr.testcaseresultsid = lt.tcrid
    left join grouping g on g.groupid = lt.groupid
    where lt.tcrid = NEW.testcaseresultsid
    into gid, blobpassed
于 2012-07-30T12:31:23.393 に答える