gpt4 book ai didi

sql - 在 UPDATE 语句中使用 HAVING 子句

转载 作者:行者123 更新时间:2023-12-04 02:59:30 26 4
gpt4 key购买 nike

这个查询

SELECT
FirstName, LastName, NCAAStats.AccountId, College_Translator.school_name, StatTypeId, COUNT(*) AS 'Count'
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
ORDER BY 'Count' DESC

选择我想设置的记录 ISValid位到 0 .

这些记录是由于输入错误而在我的数据库中出现两次的记录。

我正在寻找类似的东西:
UPDATE NCAAstats
SET IsValid = 0
WHERE (my select statement)

这是在 MS SQL SERVER 2008 上

谢谢!

最佳答案

您可以像这样加入该子查询:

update n1 set
isvalid = 0
from
ncaastats n1
inner join (
SELECT
FirstName, LastName, NCAAStats.AccountId, College_Translator.school_name, StatTypeId, COUNT(*) AS 'Count'
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
) n2 on
n1.accountid = n2.accountid

关于sql - 在 UPDATE 语句中使用 HAVING 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8793914/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com