안녕하세요
쿼리를 공부해보고 있는데요
원하는 데이터 결가값을 출력하고싶은데 아무리 해도 안되네요 ㅠㅠ
예를 들어서
A 는 로그인 기록 테이블이고
B는 ID 테이블이라고 한다면
한 유저가 B 테이블의 ID로 로그인 하면 A테이블에 기록이 남습니다.
아이다가 aaaa,bbbb,cccc,dddd
가 있고 aaa가 로그인을 3번, cccc가 로그인을 2번 했고 bbbb와 dddd가 로그인을 0번 했으면
A | B
____________
3 | aaaa
0 | bbbb
2 | cccc
0 | dddd
이런 데이터를 출력하고싶은데 쿼리가 너무 어려워서요
도움좀 부탁드립니다.
Comment 3
-
이리
2014.11.24 13:47
-
Sinlay
2014.11.24 13:48
답변감사합니다.
해결방법은
Group by All 이였네요 ㅠㅠ
초급자다보니까 질문도 하기 어렵네요 ㅠㅠ
감사합니다
-
Terry
2014.11.24 13:52
with A As
(
select 'id1' as idno union all
select 'id2' as idno union all
select 'id3' as idno union all
select 'id4' as idno union all
select 'id5' as idno union all
select 'id6' as idno
)
Select A.idno
,COUNT(B.log_cnt)
From A
Left Outer Join
(
Select 'id1' as idno,'1' as log_cnt union all
Select 'id1' as idno,'1' as log_cnt union all
Select 'id3' as idno,'1' as log_cnt union all
Select 'id5' as idno,'1' as log_cnt union all
Select 'id5' as idno,'1' as log_cnt union all
Select 'id5' as idno,'1' as log_cnt
) As B
On A.idno = B.idno
Group By A.idno
정확하게 이해를 한건지 모르겠지만..
아이디를 기준으로 COUNT() 함수를 사용하시면 될거 같네요.