這裏我們比較基因表記錄:首先將基因a與所有基因a,b,c進行比較,例如aa,ab,ac同樣需要b然後ba,bb ,bc等.......SQL查詢比較單個表中的行
所以這裏匹配的結果是nd b是2,因爲匹配記錄是589,822 bc count的常用基因條件是1,因爲匹配記錄586和它應該是所有其他組合零。
goterm gene auto
--------------------
589 a 1
822 a 2
478 a 3
586 b 4
589 b 5
600 c 6
586 c 7
822 b 8
查詢:
select count(*),
x.gene,
x.ng
from (select t.gene,
v.gene as ng
from (select distinct gene
from gene) as t
cross join (select distinct gene from gene) as v) as x
left join (select (g.gene),(n.gene) as ng from gene g
join gene n on n.goterm=g.goterm where g.auto<n.auto) as y on y.gene = x.ng
and y.ng = x.gene
group by x.gene,x.ng
最後上面查詢的輸出是:
count gene gene
1 a a
2 b a
1 c a
1 a b
1 b b
1 c b
1 a c
1 b c
1 c c
但輸出必須:
count gene gene
0 a a
2 b a
0 c a
0 a b
0 b b
1 c b
0 a c
0 b c
0 c c
您應該考慮爲「基因」字段的唯一值設置另一個表格,特別是如果您想要表示的基因有屬性。這將使生產組合更簡單。 – Simon 2010-10-28 16:21:08
@OMG Ponies,@Joe Stefanelli:如果可以,我會幫你格式化這個問題:) hehe – Andomar 2010-10-28 16:27:23