[英]How do I count three different distinct values and group on an ID in MS-Access?
[英]How do I count distinct values from same id?
如果每個ID重復一些,如何計算列中的不同值?
我已經嘗試了COUNT,DISTINCT,CASE和其他所有功能,但是我無法為每個ID計算不同的值。 我有一張這樣的桌子。
ID Symptom
1 Headache
1 Headache
1 Hematuria
1 Leg pain
1 Headache
2 Cough
2 Headache
2 Cough
3 Cough
3 Cough
3 Cough
我想獲得這樣的東西。
ID Symptom
1 Headache
1 Hematuria
1 Leg pain
2 Cough
2 Headache
3 Cough
或如何獲得總數? 像有5種不同的症狀,但沒有11種症狀(如果使用DISTINCT,我將得到4種症狀)。
你需要distinct
使用select
語句:
select distinct id, Symptom
from table t;
如果您需要唯一計數,請在count()
使用它:
select id, count(distinct Symptom)
from table t
group by id;
只需按這些字段分組:
SELECT ID, Symptom
FROM Symptoms
GROUP BY ID, Symptom
小提琴: http ://sqlfiddle.com/#!18/48dde/2/0
嘗試這個:
SELECT ID, Symptom
FROM MY_TABLE
GROUP BY 1,2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.