2013-10-19 204 views
1

早上好。我有這個表:MySQL查詢平均值

mysql> select * from Data; 
+---------------------------+--------+-------+ 
| affyId     | exptId | level | 
+---------------------------+--------+-------+ 
| 31315_at     | 3  | 250 | 
| 31324_at     | 3  | 91 | 
| 31325_at     | 1  | 191 | 
| 31325_at     | 2  | 101 | 
| 31325_at     | 4  | 51 | 
| 31325_at     | 5  | 71 | 
| 31325_at     | 6  | 31 | 
| 31356_at     | 3  | 91 | 
| 31362_at     | 3  | 260 | 
| 31510_s_at    | 3  | 257 | 
| 5321_at     | 4  | 90 | 
| 5322_at     | 4  | 90 | 
| 5323_at     | 4  | 90 | 
| 5324_at     | 3  | 57 | 
| 5324_at     | 4  | 90 | 
| 5325_at     | 4  | 90 | 
| AFFX-BioB-3_at   | 3  | 97 | 
| AFFX-BioB-5_at   | 3  | 20 | 
| AFFX-BioB-M_at   | 3  | 20 | 
| AFFX-BioB-M_at   | 5  | 214 | 
| AFFX-BioB-M_at   | 7  | 20 | 
| AFFX-BioB-M_at   | 8  | 40 | 
| AFFX-BioB-M_at   | 9  | 20 | 
| AFFX-HSAC07/X00351_M_at | 3  | 86 | 
| AFFX-HUMBAPDH/M33197_3_st | 3  | 277 | 
| AFFX-HUMTFFR/M11507_at | 3  | 90 | 
| AFFX-M27830_3_at   | 3  | 271 | 
| AFFX-MurIL10_at   | 3  |  8 | 
| AFFX-MurIL10_at   | 5  |  8 | 
| AFFX-MurIL10_at   | 6  |  4 | 
| AFFX-MurIL2_at   | 3  | 20 | 
| AFFX-MurIL4_at   | 5  | 78 | 
| AFFX-MurIL4_at   | 6  | 20 | 
| U95-32123_at    | 1  | 128 | 
| U95-32123_at    | 2  | 128 | 
| U98-40474_at    | 1  | 57 | 
| U98-40474_at    | 2  | 57 | 
+---------------------------+--------+-------+ 
37 rows in set (0.00 sec) 

如果我想尋找在所有實驗的每個陣列探測器(affyId)的平均表達水平(水平),我做SELECT affyId, AVG(level) AS average FROM Data GROUP BY affyId;

不過,我想不出如何查找每個實驗的每個陣列探針(affyId)的平均表達水平......它必須與最後一個查詢類似,但我沒有獲得好的結果......有什麼幫助?

PD:有人告訴我如果有人解決我的問題,我應該給一些聲望或點擊某個綠色按鈕...是不是?我該怎麼做?我是這個網站很新...

+0

您可以通過單擊答案分數下的複選標記標記答案爲已接受。當你有15點聲望時,你也可以快速回答。 –

回答

0

這會爲每個affyId平均:

SELECT affyId, AVG(level) AS average FROM Data GROUP BY affyId 

這平均爲每exptId :

SELECT exptId, AVG(level) AS average FROM Data GROUP BY exptId 

並且這是每個affidId中每個exptId的平均值:

SELECT affyId, exptId, AVG(level) AS average FROM Data GROUP BY exptId, affyId 
0

只需添加到group by條款

SELECT affyId, exptId, AVG(level) AS average 
FROM Data 
GROUP BY affyId, exptId;