Solved

How do I count records from a Statement, however if the same record is multiple, then count them together

Posted on 2015-02-06
14
77 Views
Last Modified: 2015-02-08
want to show a count of some records

however some records values will be the same, so I want these counted as multiple.

eg
SYD 1
MEL 2
DPS 4

not
SYD
MEL
DPS
MEL
DPS
DPS
DPS

is there a way of showing this?
0
Comment
Question by:Graeme
  • 6
  • 3
  • 2
  • +2
14 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 300 total points
ID: 40595082
using a query

select [FieldName], Count([FieldName])
from tableName
group by  [FieldName]
0
 

Author Comment

by:Graeme
ID: 40595090
Thanks for that I have correct my query so that it works

Set KPIsDest=oConn.Execute("SELECT enq_dest,COUNT(enq_dest) FROM enq WHERE enq_date BETWEEN #"&SOMonth&"# AND #"&EOMonth&"# GROUP BY enq_dest")                                          

How do I show the count of each record?

eg
SYD 1
MEL 2
DPS 4
0
 
LVL 11

Expert Comment

by:Wilder1626
ID: 40595092
You can also try:
select distinct  [FieldName], Count([FieldName]) from tableName
group by  [FieldName]
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 11

Expert Comment

by:Wilder1626
ID: 40595095
Or
select count(distinct FieldName), FieldName
from tableName
group by  FieldName
0
 
LVL 30

Expert Comment

by:hnasr
ID: 40595097
Since this is just a simple function in access, I might suggest using the query wizard to find Duplicates.
Then you may modify the query by removing the >1 criteria, either in design view or sql view.

This helps in improving your access programming. You may modify the query to get other functions, like Sum or Count, by replqacing Count or adding to it.
0
 

Author Comment

by:Graeme
ID: 40595159
Hey all, just need the code to show the records and how many of each
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40595214
where do you want to show the records?
0
 

Author Comment

by:Graeme
ID: 40595216
As a list

eg
SYD 1
MEL 2
DPS 4

is this what you meant?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40595225
As a list , where ?
0
 

Author Comment

by:Graeme
ID: 40595244
Sorry I do not get what you mean by 'where' ?

Here is the code:

<%
Set KPIsDest=oConn.Execute("SELECT enq_dest,COUNT(enq_dest) FROM enq WHERE enq_date BETWEEN #"&SOMonth&"# AND #"&EOMonth&"# GROUP BY enq_dest")							
%>
	<tr>
		<td colspan=8 align=center>Destinations</td>
		<td colspan=2>&nbsp;</td>
	</tr>
	<tr>
		<td height=20 width=20% colspan=2>0%</td>
		<td height=20 width=20% colspan=2>25%</td>
		<td height=20 width=20% colspan=2>50%</td>
		<td height=20 width=20% colspan=2>75%</td>
		<td height=20 width=20% colspan=2>100%</td>
	</tr>
<%
	Do While Not KPIsDest.eof
%>
	<tr>
		<td colspan=8>
			<table width=100% border=0>
				<tr>
					<td height=20 bgcolor=black width=<%=FormatNumber(((!!!!!!!/EnqCount)*100),2)%>%></td>
					<td height=20>&nbsp;</td>
				 </tr>
			</table>
		</td>
		<td><%=KPIsDest("enq_dest")%></td>
		<td><%=FormatNumber(((!!!!!!!!!/EnqCount)*100),2)%>% Destinations Strikerate</td>
	</tr>
<%
	KPIsDest.MoveNext 
		LOOP
	KPIsDest.Close
%>

Open in new window


where i have the !!!!! is where i need the sum count total of the destinations
0
 
LVL 84
ID: 40595489
So you want to show this on a web page. That's what Rey was asking. We don't know what programming environment you're using, so asking us "how to  show a list" doesn't make much sense to us.

You'd have to loop through the recordset and add rows to your table:

Do Until kpIsDest.EOF
<tr>
            <td colspan=8>
                  <table width=100% border=0>
                        <tr>
                              <td height=20 bgcolor=black width=<%=FormatNumber(((kpIsDest("YourNumberColumn")/EnqCount)*100),2)%>%></td>
                              <td height=20>&nbsp;</td>
                         </tr>
                  </table>
            </td>
            <td><%=KPIsDest("enq_dest")%></td>
            <td><%=FormatNumber(((kpIsDest("YourNumberColumn")/EnqCount)*100),2)%>% Destinations Strikerate</td>
      </tr>
Loop
0
 

Author Comment

by:Graeme
ID: 40596718
hello and thanks for clarifying...

KPIsDest("YourNumberColumn") being what ?

what do you need from me to figure out which column i am looking for?
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 200 total points
ID: 40596749
YourNumbercolumn is the column from your SQL statement which would contain the value you want to show. It would be either "eng_dest", or the COUNT(eng_dest) column. Since I assume it's the COUNT column, you might change the SELECT statement to this:

SELECT enq_dest, COUNT(enq_dest) AS DestCount FROM enq WHERE enq_date etc etc

Then refer to it like this:

kpIsDest("DestCount")
0
 

Author Closing Comment

by:Graeme
ID: 40597492
Cheers all for your help!

works a treat!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question