2012-10-24 82 views
0

我有兩個表。一個是「探針」,另一個是「成績單」。計數和加入表

探測表: 「探針」

ProbeID ------- TranscriptID ----

2655  4555555 
2600  5454542 
2600  4543234 
2344  5659595 

...等

成績單表: 「成績單」

TranscriptID ---- Location ----

7896736  chr1 
5454542  chr1 

...等

我需要找出每個染色體有多少個轉錄本?每個染色體有多少個探針?

SELECT COUNT(*) 
FROM transcript 

='28869'#我想我給了我每個染色體的轉錄本(即位置)。

我需要幫忙回答第二部分(和第一部分,如果它錯了)。我假設我需要使用JOIN條款。

謝謝。

回答

0

每chromosone

SELECT Location, COUNT(ProbeID) AS ProbeCnt 
FROM transcript T 
JOIN probe P ON P.TransciprtID = T.TranscriptID 
GROUP BY Location 
-- optionally you can ORDER BY to either get 
-- ORDER BY COUNT(ProbID) DESC -- list in descending order of nb of probes 
-- ORDER BY Location   -- list in order of chromosome name 

探測的次數作爲第一個查詢是不正確。爲了得到
染色體轉錄物的數量,你需要

SELECT Location, COUNT(TranscriptID) as TransCnt 
FROM transcript 
GROUP BY Location 

您當前的查詢給出的成績單總數爲整個談話表,無論染色體。

0

成績單計數

select location, count(location) AS transacripts_num 
from transcript GROUP by location; 

探測次數

select location, count(location) AS probe_num 
from transcript t join probe p 
ON t.transcriptId= p.probeId 
GROUP by location;