Hi,
I have some basic SQL experience (more programming and EXCEL
experience) and I am having a hard time generating a particular query.
My table is a historical database with columns (station,name,v alue,
time) for each time stamp and station there may be up to 50 records
each with a different name. What I want to do is for each value of
station retrieve the values for names matching key1,key2, and key3 at
the time key0 is at it's maximum. The query below works correctly for
station JOHN, but I don't want to have to cut and paste this query for
each station. Essentially I'd like to loop through each station and
perform this same query with JOHN being the replaced by the looped
station name. I've tried several variants with no success any ideas?
SELECT DB.STATION, DB.NAME, DB.VALUE, DB.TIME
FROM DB
WHERE (((DB.TIME)=(SE LECT TOP 1 DB.TIME
FROM DB
WHERE (((DB.TIME)>#11/30/2005 23:59:59#) AND
((DB.TIME)<#3/1/2006 23:59:59#) AND
((DB.STATION)=' JOHN') AND
((DB.NAME)='KEY 0')) ORDER BY DB.VALUE DESC)
)
AND
((DB.STATION)=' JOHN' AND
(DB.NAME) LIKE 'KEY1' AND
(DB.NAME) LIKE 'KEY2' AND
(DB.NAME) LIKE 'KEY3'));
Thank you.
Jim 4 1935
Jim,
are all the Station values in a table somewhere? If so (or you could
put them into one), then you could just join to the filtered table. A
really simple example would be:
DB.STATION, DB.NAME, DB.VALUE, DB.TIME
FROM DB inner join tblStation ON DB.Station=Stat ion.StationName
AND Station.Station Name IN (...some subselect query here)
That way you could pretty easily filter for just the records you want
by building the list of stations you wanted (with a query) and then
including that in your second query.
eg
SELECT DB.*
FROM DB INNER JOIN qrySomeQuery ON DB.FieldX=qrySo meQuery.FieldY
WHERE...
Hope this helps.
I assume you are viewing the query results in a form. What you can do
is to make that a subform and place it in another form which would be
your main form (or whatever name you want). In the main form you can
have a combobox with a list of the stations. Then, in the query in the
criteria section of the stations field you can make a reference to the
combobox on the main form
field: Station
criteria: Forms!mainFrom! combo1
Then when you select a station from the combobox on the form, the query
will query on that station. You will need to add a teeny bit of code to
the combobox. Go to the Form design to the Combobox Properties sheet.
Scroll down to toward the bottom of the property sheet for the combobox.
When you see a listing that says "After Update" go to the right of that
and click on the elipse ... button. Select "Code". Here you will write
the following:
Me.yourSubformN ame.Form.Requer y
Replace "yourSubformNam e" with the name of the form where you view your
query results (make sure that form is in datasheet view) which is now
your subform. Now you have a more dynamic query.
Rich
*** Sent via Developersdex http://www.developersdex.com ***
Yeah, this was tricky. I broke it down into steps:
First, find the highest value of Key0 for each station:
SELECT db.Station, Max(db.Value) AS MaxOfValue
FROM db
WHERE (((db.Name)="KE Y0"))
GROUP BY db.Station;
Save this one as Query1
Now, find the time that happened:
SELECT db.Station, db.Time, db.Name
FROM db INNER JOIN Query1
ON (db.Value = Query1.MaxOfVal ue) AND (db.Station = Query1.Station)
WHERE (((db.Name)="ke y0"));
Save this one as Query2
Finally, get all the keys for that time:
SELECT db.Station, db.Name, db.Value, db.Time
FROM db INNER JOIN
Query2 ON Query2.Time = db.Time AND db.Station = Query2.Station
WHERE db.Name in ("Key0","key1", "key2","key 3")
This Should work, but no promises. Let me know if you need more help.
Chris Nebinger
All,
Thanks... This gave me a new direction to go in designing my query.
My version of
ACCESS does not like using the JOIN syntax. I'm using the "from db,
query1" syntax.
Is there a difference between the two methods?
Chris, I was able to get steps 1 and 2 working with only a slight
modification for my needs. However, the final step is killing me....
I'm getting an error message of being out ot temporary
disk space. My DB is almost 2GB with 15M records! So I'm having to go
back to the drawing
board again.... :-)
Thanks,
Jim This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Morten Gulbrandsen |
last post by:
Hi programmers, Good morning ;-)
I think something is wrong,
Running windows I believe first I have to set some password,
Which creates some user,
Then I can grant the required privileges, for some databases.
However granting privileges after setting password seems to reset some
Other access,
|
by: Sean C. |
last post by:
Helpful folks,
Most of my previous experience with DB2 was on s390 mainframe systems
and the optimizer on this platform always seemed very predictable and
consistent. Since moving to a WinNT/UDB 7.2 environment, the choices
the optimizer makes often seem flaky. But this last example really
floored me. I was hoping someone could explain why I get worse
response time when the optimizer uses two indexes, than when it uses
one. Some context:
|
by: Peter James |
last post by:
Access 97
If I select New on the Query tab of the db window, and go staight to sql
view and type in the following for example:
INSERT INTO tblMyTable ( dtDate, txtAny)
VALUES (#2003-09-03#, 'blah');
and then save the query, close it, and then reopen by clicking the design
button so it opens in sql view. The sql has changed to:
|
by: Andrew McNab |
last post by:
Hi folks,
I have a problem with an MS Access SQL query which is being used in an
Access Report, and am wondering if anyone can help.
Basically, my query (shown below) gets some records from a couple of
tables in my database using INNER JOINS and the WHERE clause to
specify the required constraints. However, I also want to read two
fields from a *single* record from a table called 'Locations' and then
apply one of these field's values...
|
by: Bec |
last post by:
I'm in desperate need of your help..
I need to build an access database and have NO idea how to do this..
Not even where to start..
It IS for school, and am not asking anyone to do my homework for me.. I
am merely asking for help, perhaps pointers as to where to begin..
I've never used access before.. I'm rather cluey when it comes to
| |
by: Neil |
last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is
upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server
at the same time. We're moving to SQL Server 2005, and, since he already has
licenses for Office Pro 2002, he wants to upgrade to that.
I've been saying that we need to upgrade to Access 2003, not 2002, even if
Office is kept at 2002. We are also looking to do a fair amount of...
|
by: Takeadoe |
last post by:
Hey Gang, I'm gearing up to retool for the upcoming deer season here in
Ohio and I could use some help with very general questions about
direction. I will be scanning nearly 210,000 forms that capture deer
harvest information. We use Verity's Teleform V9 enterprise to capture
the scanned data.
To date, I've not done any scripting (essentially VBA) and have not set
up any real fancy rules during verification. If there are bad or
missing...
|
by: hardik |
last post by:
hi friends i need help in this sql query
i have table like,
id fid
__ _____
autonumber text
and i am storing values like
|
by: Sid |
last post by:
I hope someone could help me with this.
I am trying to setup a criteria to decide when to allow/not allow
user
to click on the check box. logically it looks simple but I am not
able
to incorporate in my data access page. I have a numerical field
called
tier status and right next to it I have a checkbox. I would like to
allow user to check and uncheck the checkbox as long as the tier
|
by: jsacrey |
last post by:
Hey everybody, got a secnario for ya that I need a bit of help with.
Access 97 using linked tables from an SQL Server 2000 machine.
I've created a simple query using two tables joined by one field
between them. The join field in both tables are indexed and I'm
selecting 1 field from each table to lookup. The Access query is
taking more than 60 second to retrieve 1 record and if I execute the
same query within the Query Analyzer, it...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
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 we have to send another system
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |