一條sql話語中有兩個between and

來源:互聯網
上載者:User
一條sql語句中有兩個between and
想實現的功能:
按兩個屬性搜尋,

資料庫設計(資料庫設計已定不能更改了)
這是category_value表
這是 buy_6表
我寫的sql語句:
select b.* from category_value as v, buy_6 as b where status=3 and v.itemid = b.itemid and v.moduleid=6 and v.value BETWEEN 2 and 7 and v.oid=6 and v.value BETWEEN 1 and 10 and v.oid=4

如果只按一個資料搜尋沒問題,兩個屬性就搜尋不出資料
sql中v.oid=4指的是顏色屬性id為4,v.oid=6指的是高度屬性id為6
------解決思路----------------------
這不是 between 的問題!
在你的 sql
select b.* from category_value as v, buy_6 as b where status=3 and v.itemid = b.itemid and v.moduleid=6 and v.value BETWEEN 2 and 7 and v.oid=6 and v.value BETWEEN 1 and 10 and v.oid=4
既然 v.oid 不可能同時等於 6 和 4
那麼自然就不會有結果的
------解決思路----------------------
按你的意思,似乎應該是:
(v.value BETWEEN 2 and 7 and v.oid=6) or (v.value BETWEEN 1 and 10 and v.oid=4)
所以sql語句應該為:
select b.* from category_value as v, buy_6 as b where status=3 and v.itemid = b.itemid and v.moduleid=6 and ((v.value BETWEEN 2 and 7 and v.oid=6) or (v.value BETWEEN 1 and 10 and v.oid=4))
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.