gpt4 book ai didi

sql - 在更新语句中具有选择子查询的嵌套 SQL 查询

转载 作者:搜寻专家 更新时间:2023-10-30 20:01:46 25 4
gpt4 key购买 nike

在执行此查询时,WHERE 子句附近出现错误。

update AssetData set EmployeeName = ISNULL(EmployeeName,'') +@reasEmp 
where ([AssetNumber] like'%" + WA_number.Text + "%')
and ID IN (SELECT ID FROM AssetData ORDER BY ID DESC
where ([AssetNumber] like'%" + WA_number.Text + "%') LIMIT 1)

谁能帮我弄清楚这是怎么回事?

最佳答案

and ID IN (SELECT ID FROM AssetData ORDER BY ID DESC
where ([AssetNumber] like'%" + WA_number.Text + "%') LIMIT 1)

where 应该在 ORDER BY 之前。 in ( ... limit 1) 虽然合法,但没有意义,因为 in 应该与列表一起使用。我建议改用 = max(ID)

and ID = (SELECT max(ID) FROM AssetData where [AssetNumber] like'%" + WA_number.Text + "%')

您可以省略 where 子句的第一部分,因为 ID 已经符合相同的条件

update AssetData set EmployeeName = ISNULL(EmployeeName,'') +@reasEmp 
where ID = (SELECT max(ID) FROM AssetData where [AssetNumber] like'%" + WA_number.Text + "%');

关于sql - 在更新语句中具有选择子查询的嵌套 SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27716244/

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