나는이 문제를 한동안 해결하려고 노력해 왔으며 누군가가 나를 도울 수 있기를 바랍니다. 두 개의 테이블이 있는데 첫 번째 테이블은
테이블 명 : OnlineTest
OnlineTestId category subcategory
1 English Spelling
2 English Grammar
3 English Antonyms
4 English Synonyms
두 번째 테이블은
테이블 이름 : UserStatus
Id userId status onlineTestId
1 1 Finished 1
2 1 Not Finished 2
3 2 Not Finished 1
4 2 Finished 3
5 3 Not Finished 4
결과
OnlineTestId userId status
1 1 Finished
2 1 Not Finished
3 null null
4 null null
이 쿼리를 시도했습니다.
select c.onlinetestid, d.userid, d.status from onlinetest c left join userstatus d on d.onlinetestid = c.onlinetestid
where c.category = 'English' and d.userid = 1;
그러나이 쿼리는 userId와 status가 null 인 마지막 두 행이 아니라 결과의 처음 두 행을 가져옵니다.
위의 결과를 가져 오는 방법은 무엇입니까?
절에 d.userid = 1
술어를 넣으십시오 ON
.
select c.onlinetestid, d.userid, d.status
from onlinetest c
left join userstatus d on d.onlinetestid = c.onlinetestid and d.userid = 1
where c.category = 'English'
이것은 술어 가 실패 하는 s로 채워진 onlinetest
열을 가진 모든 행을 반환 합니다.userstatus
null
d.userid = 1
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다