一個MySql查詢問題
問題描述
數據如下:
idcol1a,b,d 2a,b,c
我的查詢條件:
col=(a,b) 要求查到id為1,2的兩行
col=(a,d) 查到id為1的行
col=(a,c) 查到id為2的行
col=(a) 查到id為1,2的兩行
請教下大家有沒有什么方法呢?
問題解答
回答1:以第一個為例。
select * from tablename where find_in_set(’a’, col)>0 and find_in_set(’b’, col)>0;回答2:
1.SELECT * FROM test_findisset where find_in_set(’a’,col) and find_in_set(’a’,col) and find_in_set(’b’,col)
2.SELECT * FROM test_findisset where find_in_set(’a’,col) and find_in_set(’a’,col) and find_in_set(’d’,col)
3.SELECT * FROM test_findisset where find_in_set(’a’,col) and find_in_set(’a’,col) and find_in_set(’c’,col)
4.SELECT * FROM test_findisset where find_in_set(’a’,col) and find_in_set(’a’,col)
相關文章:
1. java - spring 4.+ 利用reponse 下載文件看不到文件到底有多大,但是能下載成功 ?2. mysql - sql 優化問題,between比in好?3. javascript - 請問 chrome 為什么會重復加載圖片資源?4. 個人主頁博客統計中的“進入博客”不能點擊5. pycharm運行python3.6突然出現R6034問題,請問如何處理?6. html - flask后臺傳一個null到前端7. java - 為什么hibernate查詢表集報錯?8. mysql 5個left關鍵 然后再用搜索條件 幾千條數據就會卡,如何解決呢9. mysql - 字符串根據字典替換10. 就一臺服務器,mysql數據庫想實現自動備份,如何設計?
