mySQL 查詢,該怎麼處理

來源:互聯網
上載者:User
mySQL 查詢
有這樣一個表
user_id(使用者id)ques_id(問題id)their_answer(他們的回答)my_answer(我的回答)
要實現的是 使用者的id和所有的id進行比較 尋找回答的相同的題,並且尋找出相同的題的我的回答和他們的回答,
求高手幫忙寫出一個快速查詢的sql語句,

------解決方案--------------------
這個意思?
SQL code
select a.user_id,a.my_answer from question a inner join (select ques_id from question where user_id=1 ) t on a.ques_id=t.ques_id
------解決方案--------------------
自串連
select a.* from question a, question b where a.ques_id = b.ques_id and b.user_id=使用者1的id

select a.* from question a, question b where a.ques_id = b.ques_id and b.user_id in (,使用者1的id,使用者2的id)


------解決方案--------------------
帶條件怎麼會顯示所有的id?

另外自串連要避免自己跟自己串連
select a.* from question a, question b where a.ques_id = b.ques_id and a.user_id <> b.user_id and b.user_id = '使用者1的id'
  • 聯繫我們

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