4

hello need a update starting from..

 SELECT 
     tA.id, count(*) c
FROM
    tA
        join
    tA ON tB.id = tA.id
where
    tA.id = 5
GROUP BY tA.id
having c > 1;

I have a relational model one to many. but need include the count in the update

   UPDATE tA
        join
    tA ON tB.id = tA.id 
set 
    cnt = 5;

assuming that this is the result of the count

where 'c' is the first select count... may be.

UPDATE tA
        join
    tA ON tB.id = tA.id 
set 
    cnt = (SELECT 
            count(*) c
        FROM
            tA
                join
            tA ON tB.id = tA.id
        WHERE
            tA.id = 5
        GROUP BY tA.id
        having c > 1);

say query syntax nor supported.. thnk

4

1 回答 1

1
UPDATE  tA
        INNER JOIN
        (
            SELECT  tA.id, COUNT(*) totalCount
            FROM    tA INNER JOIN tB ON tB.id = tA.id
            WHERE   tA.id = 5
            GROUP   BY tA.id
            HAVING  COUNT(*) > 1
        ) b ON tA.id = b.id
SET     tA.cnt = b.totalCount
于 2013-05-17T02:30:10.503 回答