gpt4 book ai didi

java - 谁能帮我解决这个sql查询

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

我在 PreparedSentence 中有以下包含 SQL 查询的代码:

public final ProductInfoExt getProductInfoByCode(String sCode, String siteGuid) throws BasicException {
if (sCode.startsWith("977")) {
// This is an ISSN barcode (news and magazines)
// the first 3 digits correspond to the 977 prefix assigned to serial publications,
// the next 7 digits correspond to the ISSN of the publication
// Anything after that is publisher dependant - we strip everything after
// the 10th character
sCode = sCode.substring(0, 10);
}
return (ProductInfoExt) new PreparedSentence(s, "SELECT "
+ getSelectFieldList()
+ " FROM STOCKCURRENT AS C RIGHT JOIN PRODUCTS P ON (C.PRODUCT = P.ID) "
+ " WHERE P.CODE OR (P.REFERENCE = ? ) AND C.SITEGUID = ? ",
new SerializerWriteBasicExt(new Datas[]{Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING}, new int[]{0, 1}),
ProductInfoExt.getSerializerRead()).find(sCode, siteGuid);
}

如果我通过 P.CODE 使用搜索,效果会很好: WHERE P.CODE = ? AND C.SITEGUID = ?。但是,假设我希望它在 P.REFERENCE 中找到结果(如果 P.CODE 中没有任何匹配项)。我尝试执行这样的代码语句,但没有成功: WHERE P.CODE OR P.REFERENCE = ? AND C.SITEGUID = ?,但我收到错误。任何帮助将不胜感激。

最佳答案

OR 语句进行分组

return (ProductInfoExt) new PreparedSentence(s, "SELECT "
+ getSelectFieldList()
+ " FROM STOCKCURRENT AS C RIGHT JOIN PRODUCTS P ON (C.PRODUCT = P.ID) "
+ " WHERE (P.CODE = ? OR P.REFERENCE = ?) AND C.SITEGUID = ? ",
new SerializerWriteBasicExt(new Datas[]{Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING}, new int[]{0, 1, 2}),
ProductInfoExt.getSerializerRead()).find(sCode, sCode, siteGuid);

关于java - 谁能帮我解决这个sql查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58295958/

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