표 :SQL 체크 여러 행이
id | name | country
---------------------
1 | abc | India
2 | abc | America
3 | abc | USA
4 | xyz | India
5 | xyz | America
6 | xyz | USA
QUERY 지금까지 시도 :
SELECT `id`,
if(`country` = 'India',count(id),0) as object1,
if(`country` = 'America', count(id),0) as object2,
if(`country` = 'USA',count(id),0) as object3
FROM `table`
위 같은 나에게 출력을 제공 :
id | name | object1 | object2 | object3
---------------------------------------------
1 | India | 6 | 0 | 0
다음과 같이 출력하고 싶습니다.
id | name | object1 | object2 | object3
---------------------------------------------
1 | India | 1 | 1 | 1
1 | America | 1 | 1 | 1
1 | USA | 1 | 1 | 1
이 출력물을 얻으려는 사람이 있습니까?
개체 수는 무엇입니까? object1/object2/object3 수와 다른 값의 전체 빈도 간에는 어떤 관계도없는 것 같습니다. GROUP BY와 name, count (*)를 사용할 수 없습니까? – MatsLindh