亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

誰能幫我解決這個sql查詢

誰能幫我解決這個sql查詢

翻閱古今 2023-10-12 14:55:02
我有以下帶有 SQL 查詢的代碼PreparedSentence: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但是,假設我希望它在if 中沒有匹配的情況下找到結果P.CODE。我嘗試執行這樣的代碼語句,但沒有成功:WHERE P.CODE OR P.REFERENCE = ? AND C.SITEGUID = ?,但收到錯誤。任何幫助將不勝感激。
查看完整描述

2 回答

?
揚帆大魚

TA貢獻1799條經驗 獲得超9個贊

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);


查看完整回答
反對 回復 2023-10-12
?
繁星coding

TA貢獻1797條經驗 獲得超4個贊

你的語法錯誤,應該是

WHERE (P.CODE = ?  OR P.REFERENCE = ?) AND C.SITEGUID = ?

然后你需要設置第三個參數


查看完整回答
反對 回復 2023-10-12
  • 2 回答
  • 0 關注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號