單表多條件淘選交集60分在另外的板塊,完成進去另外領分

來源:互聯網
上載者:User
單表多條件式篩選交集60分在另外的板塊,完成進去另外領分
這是資料表
BuyID AttributeID Value
1 1 單間出租
1 2 0
1 3 1
1 4 1000
2 1 整套出租
2 2 地址
2 3 1
2 4 1000
3 1 單間出租
3 2 9
3 3 10
3 4 1500

條件一:`AttributeID`=1 AND `Value`='單間出租'
條件二:`AttributeID`=4 AND `Value`>=1000 AND `Value`<=2000

我改如何搜尋出條件一和條件二的交集呢?
即搜尋出的結果只有一條,`BuyID`=1

嘗試一:SELECT * FROM jm_user_buy_attribute WHERE (`AttributeID`=1 AND `Value`='單間出租') OR (`AttributeID`=4 AND `Value`>=1000 AND `Value`<=2000) GROUP BY BuyID
嘗試一搜尋出來的結果只是滿足條件一或者條件二的結果,但不能篩選出交集。

嘗試二:SELECT * FROM jm_user_buy_attribute WHERE (`AttributeID`=1 AND `Value`='單間出租') OR (`AttributeID`=4 AND `Value`>=1000 AND `Value`<=2000) GROUP BY BuyID
嘗試二搜尋出來的結果只是去除了相同的BuyID

嘗試三:SELECT * FROM jm_user_buy_attribute as b1 left join jm_user_buy_attribute as b2 on b1.BuyID=b2.BuyID where b1.AttributeID=1 AND b1.Value='單間出租' OR b2.AttributeID=4 AND b2.Value>=1000 AND b2.Value<=2000
嘗試二搜尋出來的結果不正確。


http://bbs.csdn.net/topics/390325234
這是我在MYSQL板塊那裡發布過的!
解決問題後可以請進去領分


------解決方案--------------------
單獨 select * from jm_user_buy_attribute where AttributeID=1 AND Value='單間出租'
得
Array
(
[0] => Array
(
[BuyID] => 1
[AttributeID] => 1
[Value] => 單間出租
)

[1] => Array
(
[BuyID] => 3
[AttributeID] => 1
[Value] => 單間出租
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.