Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subquery grouping question 1

Status
Not open for further replies.

ychousa

MIS
Jun 11, 2003
82
US
Hi. I have a tblContact_Ken with ID, SOURCE, SOLD(YES/NO), LASTDATE.

Here's my query:
SELECT tblContact_Ken.SOURCE, Count(tblContact_Ken.ID) AS Leads, Round(Count(ID)/(SELECT count(ID) from tblContact_Ken WHERE (((tblContact_Ken.LASTDATE) Between [Start Date] And [End Date])))*100) AS Percentage
FROM tblContact_Ken
WHERE (((tblContact_Ken.LASTDATE) Between [Start Date] And [End Date]))
GROUP BY tblContact_Ken.SOURCE
ORDER BY Count(tblContact_Ken.ID) DESC;

The result looks like this:
SOURCE LEADS PERCENT
PREVENTION 50 33
READERS DIGST 40 22
..

What I want to do is to get the total number sold for each grouped source and percentages, so this is what I want.
SOURCE LEADS PERCENT SOLD PERCENT(SOLD/LEADS)
PREVENTION 50 33 10 20%
READERS DIGST 40 22 10 25%

This is so confusing to me. I really need some help.

Thanks in advance!

 
To get the number of sold items you can use

Code:
sum(iif(sold,1,0))

Shouldn't be any problem calculating the %
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top