G
Geoff Greene
I've hit a deadend trying to figure out a "count distinct" type query, that
also includes a join, to add fields from a second table to the distincts
found in the first. My table look like this, and a many-to-one from
tbl.Quote to tbl.Company on Accountno
tbl.Company
Accountno | Company | etc
1111 | ABC Co |
1112 | DEF Co |
1113 | GHI Co |
tbl.Quote
Accountno | Quote | Status | etc
1111 | 001 | Closed |
1113 | 002 | Open |
1111 | 003 | Open |
1113 | 004 | Open |
1112 | 005 | Closed |
I'm trying to generate a list of companies that have one or more quotes with
a status of "Open", and a count of how many "Open" quotes each company has.
I can write a single-table query against tbl.Quote, that returns each
Accountno with a count of it's "Open" quotes, like this-
select Accountno, count(*) from tbl.Quote
where Status = "Open"
group by Accountno
which would return-
Accountno | Count
1111 | 1
1113 | 2
Now I want to pull in the Company field from tbl.Company, so I can display
the company names instead of their account numbers. But everything I've
tried to pull in Company causes an error in either the Count of GroupBy.
I've searched through related posts, but couldn't find anything that seemed
to fit. Any suggestions would be much appreciated.
Thanks,
Geoff
also includes a join, to add fields from a second table to the distincts
found in the first. My table look like this, and a many-to-one from
tbl.Quote to tbl.Company on Accountno
tbl.Company
Accountno | Company | etc
1111 | ABC Co |
1112 | DEF Co |
1113 | GHI Co |
tbl.Quote
Accountno | Quote | Status | etc
1111 | 001 | Closed |
1113 | 002 | Open |
1111 | 003 | Open |
1113 | 004 | Open |
1112 | 005 | Closed |
I'm trying to generate a list of companies that have one or more quotes with
a status of "Open", and a count of how many "Open" quotes each company has.
I can write a single-table query against tbl.Quote, that returns each
Accountno with a count of it's "Open" quotes, like this-
select Accountno, count(*) from tbl.Quote
where Status = "Open"
group by Accountno
which would return-
Accountno | Count
1111 | 1
1113 | 2
Now I want to pull in the Company field from tbl.Company, so I can display
the company names instead of their account numbers. But everything I've
tried to pull in Company causes an error in either the Count of GroupBy.
I've searched through related posts, but couldn't find anything that seemed
to fit. Any suggestions would be much appreciated.
Thanks,
Geoff