Using a HAVING clause in an UPDATE statement

前端 未结 5 2205
栀梦
栀梦 2020-12-09 18:24

This query

SELECT
FirstName, LastName, NCAAStats.AccountId, College_Translator.school_name, StatTypeId, COUNT(*) AS \'Count\'
FROM NCAAstats
INNER JOIN Colle         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 19:30

    The above are good suggestions.... here's another easy way to do it :

    update ncaastats set isvalid = 0
    where accountId in (
        SELECT AccountId
        FROM NCAAstats
        INNER JOIN College_Translator
        ON College_Translator.AccountID = NCAAstats.AccountId
        GROUP BY FirstName, LastName, NCAAStats.AccountId, College_Translator.school_name, CalendarYear, StatTypeId
        HAVING COUNT(*) >1
    ) 
    

    ** Forgive me if I messed up the columns name, but you get the idea.

提交回复
热议问题