2017-05-04 85 views
1

我有一張表,用於存儲讀寫用戶的點數,以及滿足每個用戶需求的點數。這裏有一個例子:SQL比較表中的數據

User | READING_PNTS | READING_REQ | WRITING_PNTS | WRITING_REQ 
jim |  3  |  8  |  6  |  5 
tim |  7  |  4  |  6  |  3 
kim |  7  |  5  |  2  |  5 
Ron |  6  |  4  |  8  |  4 
Dom |  10  |  7  |  6  |  3 
ton |  3  |  5  |  6  |  5 

我得到的表應該是簡單的誰滿足需求,誰不符合這兩個要求的脂肪酶數量的脂肪酶數量。所以在這種情況下,它會是這樣的:

Meet | Not Meet 
3 | 3 

任何幫助,將不勝感激。另外,我正在Access中進行備案。 謝謝!

回答

1

我覺得你只是想有條件的聚集,這在MS Access使用iif()swtich()

select sum(iif(reading_pnts >= reading_req and writing_pnts >= writing_req, 1, 0)) as meet, 
     sum(iif(reading_pnts >= reading_req and writing_pnts >= writing_req, 0, 1)) as not_meet 
from t;