Re: [SQL ] 查詢符合條件的欄位數值

看板Database (資料庫)作者 (carl)時間14年前 (2012/01/16 02:22), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《jhchenzt (旅人的日記)》之銘言: : 各位好, : 我的資料庫系統是MySQL 5.0。 : 現在有三個資料表如下 : table a : ========================== : cloumn | matrix | factor : M00631 T02753 : M00631 T04494 : M00631 T04498 : M00631 T05302 : M00631 T05307 : M00631 T05308 : ... ... : M00632 ... : M00633 ... : ========================== : table b : ========================== : column | factor | gene : T02753 G004841 : T04494 G002744 : T04498 G002745 : T05302 G004842 : T05307 G002745 : T05308 G002745 : ... ... : ========================== : table c : ========================== : column | gene | os : G004841 mouse : G002744 horse : G002745 human : G004842 dog : ========================== : 也就是說, : matrix相同的情況下,會對應到不同的factor。 : 而factor再各自對到gene : 最後根據gene判別他是屬於哪一物種(老鼠、人類...等等) : 現在我卡在「如何在table a抓屬於人類(human)的factor」 select b.factor from b,c where c.os = "human" and c.gene = b.gene 如果還要加上matrix的條件的話 select a.factor from a,b,c where c.os = "human" and c.gene = b.gene and b.factor = a.factor and a.matrix = "M00631" : (ex.T04498、T05307、T05308) : 但是否屬於人類,需要在table c才能得知。 : 之前我用 : select * from c join b join a where a.matrix="M00631" && c.os="human"; : 然後資料庫就當了... : 還是這需要用stored procedure做呢? : 有沒有其他好的方法可以分享一下? : 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.127.141.84
文章代碼(AID): #1F4nbcHK (Database)
文章代碼(AID): #1F4nbcHK (Database)