In Access 2007, I have a query it has 2 collumns one is "Location" and the other is titled "Activity". Lets say "Location" has 2 choices "Here" or "There". While "Activity" has several that can be done at both locations. Lets say "Eat, Drink, Rest, Run, Walk" I want to count on the rows of data incrementally how many times I run, here and add incrementally in a third collumn how many times it is done. I can have this in a new query or the existing one.
So It would look like (table example):
Run Here
Run There
Walk Here
Run There
Run Here
And the results would be
Run Here 1
Run There 1
Walk Here 1
Run There 2
Run Here 2
8 1801 @union51 Welcome to Bytes :)
Assuming to have read you right this relies on a table called Table1 having two columns Location and Activity containing the data you describe. Paste this into the SQL window of an Access query and run it. It presents three columns one being concatanated (which you can delete if you wish. Remember you must have a table called table1 or alter the references in this SQL replacing Table1 with your own - SELECT Table1.Location, Table1.Activity, [Location] & " " & [Activity] AS [Physical Activity], Count(Table1.Activity) AS Result
-
FROM Table1
-
GROUP BY Table1.Location, Table1.Activity, [Location] & " " & [Activity];
@Jim Doherty
Thank you for the quick reply....
Is there a way to count each row incrementally?
So that I could have
here run 1
here run 2
there run 1
there walk 1
here run 3
@union51
oh I get you now a running sum....well just now I am going for a meal so unless someone else contributes this in the meantime.... I will come back to you in a bit
@Jim Doherty
No problem, I had figured I could do it in a VBA loop then had no idea on how to count my instances.
Thank you for your help.
@union51
Hi again
You can play with a loop if you wish to hone your VBA skills but SQL can handle this too.
To make the running sum work add an extra field called 'id' to the table and set it to autonumber then let it fill the column with a sequence of numbers.
Now that we have a series of some numeric data available we can now obviously implement a running sum based on counting the 'id' column and significantly relate that to the location column and the activity column.
Given that we are dealing with the table called table1 as mentioned earlier. the following SQL statement will give you your running sum per location/activity as desired - SELECT LA.id, LA.Location, LA.Activity, LA.[Running Sum]
-
FROM [SELECT LA.id, LA.Location, LA.Activity, (select count([id]) FROM table1 where id <=LA.id and location=LA.location and activity=LA.activity) AS [Running Sum]
-
FROM Table1 AS LA]. AS LA
-
ORDER BY LA.Location, LA.Activity, LA.[Running Sum];
Sorry, I was out mowing my yard by popular demand.
I am getting a error on the bracket between from & select. Will try to figure it out however.
@union51
I don't know what happened there... fixed -
SELECT LA.id, LA.Location, LA.Activity, LA.[Running Sum]
-
FROM (SELECT LA.id, LA.Location, LA.Activity, (select count([id]) FROM table1 where id <=LA.id and location=LA.location and activity=LA.activity) AS [Running Sum]
-
FROM Table1 AS LA) AS LA
-
ORDER BY LA.Location, LA.Activity, LA.[Running Sum];
@Jim Doherty
Oh, well that is perfect thank you so much for the help!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Sean Dolan |
last post by:
typedef struct ntt {
int type;
union {
int i;
char* s;
};
}nt;
nt n;
n.i = 0;
|
by: Greg |
last post by:
Is it your general opinion that C# is generally designed/intended/ready to
replace C++? I know the answer is not black and white but please repond YES
or NO (add any comments if you would like)
...
|
by: salad |
last post by:
I'm curious about your opinion on setting relationships.
When I designed my first app in Access I'd go to Tools/Relationships and
set the relationships. Over time I'd go into the window and see...
|
by: Dennis D. |
last post by:
Hello:
So far I am into XML, XHTML, JavaScript, VB.net, and the .Net Framework. I
have the ability to use SQL server, MS Access, or XML as databases, and 1.1
and 2.0 are installed on the server....
|
by: casper christensen |
last post by:
Hi
When someone fills the form on my site, and id is created in my
database. (see below)
http://www.affiliatesjunction.net/directory.php?ax=out&id=XXX
after submitting the form they are...
| |
by: Fabrizio |
last post by:
My web cam save a file each minute with a name like this
"history20070611s202635195.jpg"
Do you know a script in php that can animate the last 60 jpg ? What I
like is something like this:
...
|
by: Rick A.B. |
last post by:
Article in SD Times
http://www.sdtimes.com/download/images/sdtimes179.pdf
Microsoft SQL Server is still
No. 1. According to the 2007
Database and Data Access, Integration
and Reporting...
|
by: capricious |
last post by:
Is it possible, so that when you do multiple <UL>'s to control how
deep the UL's are marked? For example, it would defaultly look like
this with multiple ULs and LIs:
-- Code :
Main...
|
by: howa |
last post by:
Just found a funny things..
in HTML4's dtd, http://www.w3.org/TR/html4/strict.dtd
language is not valid, i.e.
<!ELEMENT SCRIPT - - %Script; -- script statements -->
<!ATTLIST...
|
by: Jeremy J Starcher |
last post by:
While reading c.l.j, I've noticed that some people prefer and indeed even
recommend the use of "window.alert()" over "alert()".
I can't find any technical reason to make this distinction, and...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |