mysql - How to do a second query using the results of a previous query -
ok need count how many sales has made each of sell agents of company, this...
select agentid, agentname, count(*) total_sales sales group agentid   this works perfectly, how ever not show agents had 0 sells.
so need perform a
select agentid agents   and query of each result, can count how many sales had agent. hope explain it.
(i can loop in php, how ever im wondering if possible directly in mysql)
regards
you can want 1 query:
select a.agentid, a.agentname, count(s.agentid) total_sales agents left outer join      sales s      on a.agentid = s.agentid group a.agentid, a.agentname;   the left outer join keeps in first table (agents).  count() counting number of matches in sales table.
Comments
Post a Comment