gpt4 book ai didi

java - 查询内部查询到 1 个查询 postgresql

转载 作者:行者123 更新时间:2023-11-29 13:04:21 24 4
gpt4 key购买 nike

我有这样的问题

UPDATE FOLLOWUP F SET CUSTOMER=(SELECT NAME FROM CUSTOMERS C WHERE F.CUST_ID=C.ID), PHONE=(SELECT SEARCHKEY FROM CUSTOMERS C WHERE F.CUST_ID=C.ID);

这在我的 postgresql 中成功运行,但不能在 java 中运行

和我的java函数

for (final TicketLineInfo l : ticket.getLines())
if(l.getConsumption()!= 0.0 && l.getMultiply()!=l.getConsumption()) {
new PreparedSentence(s
, "UPDATE FOLLOWUP F SET CUSTOMER=(SELECT NAME FROM CUSTOMERS C WHERE F.CUST_ID=?), PHONE=(SELECT SEARCHKEY FROM CUSTOMERS C WHERE F.CUST_ID=?);"
, SerializerWriteParams.INSTANCE
).exec(new DataParams() { public void writeValues() throws BasicException {
setString(1, ticket.getCustomerId());
setString(2, ticket.getCustomerId());
}});
}

当我运行它时

我得到这样的错误:

com.openbravo.basic.BasicException: 
org.postgresql.util.PSQLException: ERROR: more than one row returned by a subquery used as an expression

org.postgresql.util.PSQLException:
ERROR: more than one row returned by a subquery used as an expression

我的问题是如何将上面的查询转换成一个没有子查询的查询..这样我就可以避免这个异常并继续我的执行或者是否有任何其他支持这个的序列化程序

最佳答案

看起来您的查询中不需要子查询:

update FOLLOWUP as F set
Name = c.Name,
Phone = c.SearchKey
from CUSTOMERS as c
where
F.Cust_ID = C.ID and
F.Cust_ID = ?

关于java - 查询内部查询到 1 个查询 postgresql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18755464/

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