473,378 Members | 1,280 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to analyze differences between same field values in multiple records

My database query returns records of specific events sorted by a geographic area and then by date.

Event Date Location
1 9/1/2009 New York
2 10/15/2009 New York
3 2/15/2010 New York
4 3/1/2010 New York
5 8/15/2009 Los Angeles
6 11/12/2009 Los Angeles
7 12/1/2009 Los Angeles
8 12/25/2009 Los Angeles

I am trying to have a query or report return or calculate the following:

Calc 1. The number of days between an event and the preceding event at the same location
Calc 2. Using the data returned in 1., flag occasions when the frequency of events occur within a certain timespan (example below, "IF" CALC1 is <30)

Event Date Location CALC1 CALC2
1 9/1/2009 New York ---
2 10/15/2009 New York 44
3 2/15/2010 New York 123
4 3/1/2010 New York 14 1
5 8/15/2009 Los Angeles ---
6 11/12/2009 Los Angeles 89
7 12/1/2009 Los Angeles 19 1
8 12/25/2009 Los Angeles 24 1

This is easy in a spreadsheet, but I want to have the database do the work
Sep 23 '10 #1
2 1173
TheSmileyCoder
2,322 Expert Mod 2GB
If you make your query so that it sorts by Location and then by date, you can add a calculated field:
Expand|Select|Wrap|Line Numbers
  1. NrDays: CalcDate([Location];[Date])
where CalcDate is a VBA function you have to place in a module:
Expand|Select|Wrap|Line Numbers
  1. Public Function calcDate(strLoc As String, dtDate As Date) As Integer
  2.     Static strLastLoc As String
  3.     Static dtLastDate As Date
  4.  
  5.     If strLastLoc = strLoc Then
  6.         calcDate = DateDiff("d", dtLastDate, dtDate)
  7.         dtLastDate = dtDate
  8.         Else
  9.         strLastLoc = strLoc
  10.         dtLastDate = dtDate
  11.         calcDate = 0
  12.     End If
  13. End Function
I dont know a smart way of having your second calculated field work within the same query, but you can make a new query based on this query, and then simply have a field there:
Expand|Select|Wrap|Line Numbers
  1. toOften:nrDays<30
Sep 24 '10 #2
Thanks for the answer.
Sep 24 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Doug Shokes | last post by:
All, Given multiple records with identical values in all fields except a single varchar field, is there an efficient query that will group the records into a single record and concatenate the...
3
by: Jeff Magouirk | last post by:
Dear all, I need to update one field in a table for a given record and visit number. Example below is how the table looks - SID VISIT DLCO 101 0 12 101 1 16 102 ...
1
by: ano1optimist | last post by:
I have a table that contains empno and qtr - it looks similar to: 0001 1 0001 2 0004 3 0004 4 0005 5 and I'm trying to make it look like: 0001 12 0004 34 0005 5
12
by: shank | last post by:
I'm trying to use online samples for submitting multiple records from ASP into a stored procedure. Failing! Through the below form, a user could be submitting many records at a time. I'm not...
4
by: Terren | last post by:
Is there a way to create one field from multiple records using sql. For example Table 1 John 18 Peter 18 David 18 Now I want an sql query that when executed will return a field that...
3
by: chalrav | last post by:
Reading through multiple records, with Loop capability -------------------------------------------------------------------------------- Hi, I have three tables as below: Table: Demand...
5
by: mctime | last post by:
Hello, I am attempting to split a raw data table into a new table that has split out a specific field in the raw data and created a new record for each split but I have come to an impasse due to...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
3
by: Skeeter66 | last post by:
I'm using Access 2003 SP3. I know very little about VB code, but inherited a database with some code and modules already running. I have a new table with a material number and date as the primary...
2
by: allanb | last post by:
Hi Guys, I am a newbie and need some help. I have a query that contains a list of questions together with the result per question for a group of learners. Example: Learner ID; Name, Surname,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.