A
Andreas
Hello
I have a question about outer join.
For example, we have Persons table:
Person_id | Status |
1 | active
2 | with obligations
3 | nonactive
4 | active
Then we have Lending table
Lending_id | Person_id | Lending_status_ID |
1 | 1 | 1
2 | 1 | 1
3 | 2 | 1
4 | 2 | 2
5 | 3 | 3
6 | 4 | 3
7 | 4 | 1
8 | 1 | 3
This is the result what I aim:
Person_ID | How_many_lendings_with_status_2_or_1 |
3 | 0
4 | 1
1 | 2
In other words, I want to output Person_ID's from Persons table which have
Person_status set to 'Active' or 'Nonactive' and then show how many lendings
each person have with status '1' or '2'.
This is what I have:
SELECT Persons.Person_ID, Count (Lending.Person_ID) AS LendingNumber
FROM Persons
LEFT OUTER JOIN Lending ON Persons.Person_ID = Lending.Person_ID
AND Lending.Lending_status_ID in (2,4)
WHERE Persons.Person_status IN ('active', 'nonactive')
GROUP BY Persons.Person_ID
However, Access has trouble with "Lending.Lending_status_ID in (2,4)" part.
Are there other ways to specify that to count only lendings with status 2 or
4?
Best Regards
I have a question about outer join.
For example, we have Persons table:
Person_id | Status |
1 | active
2 | with obligations
3 | nonactive
4 | active
Then we have Lending table
Lending_id | Person_id | Lending_status_ID |
1 | 1 | 1
2 | 1 | 1
3 | 2 | 1
4 | 2 | 2
5 | 3 | 3
6 | 4 | 3
7 | 4 | 1
8 | 1 | 3
This is the result what I aim:
Person_ID | How_many_lendings_with_status_2_or_1 |
3 | 0
4 | 1
1 | 2
In other words, I want to output Person_ID's from Persons table which have
Person_status set to 'Active' or 'Nonactive' and then show how many lendings
each person have with status '1' or '2'.
This is what I have:
SELECT Persons.Person_ID, Count (Lending.Person_ID) AS LendingNumber
FROM Persons
LEFT OUTER JOIN Lending ON Persons.Person_ID = Lending.Person_ID
AND Lending.Lending_status_ID in (2,4)
WHERE Persons.Person_status IN ('active', 'nonactive')
GROUP BY Persons.Person_ID
However, Access has trouble with "Lending.Lending_status_ID in (2,4)" part.
Are there other ways to specify that to count only lendings with status 2 or
4?
Best Regards