473,804 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding Minimums Over Multiple Years:

1 New Member
Here's where I stand. I have two queries. The first calculates a 7-day moving average (Avg7Day) for every day. Here's how it works:

SELECT T1.SITE_NO, T1.DATE, T1.FLOW, Avg(T2.FLOW) AS Avg7Day, Year(([T1].DATE)) AS FY
FROM [USGS RAW] AS T1 INNER JOIN [USGS RAW] AS T2 ON T1.SITE_NO = T2.SITE_NO
WHERE (((T1.SITE_NO)= "03345000") AND ((T1.DATE)>=([T2].[DATE]-3) And (T1.DATE)<=([T2].[DATE]+3)))
GROUP BY T1.SITE_NO, T1.DATE, T1.FLOW, Year([T1].DATE);

The next query is supposed to calculate a minimum the minimum 7-day average over the following year, for each day. For example, for 1/1/2001, it calculates the minimum 7-day average between 1/1/2001 and 12/31/2002. For 1/2/2001, it calculates the minimum 7-day average between 1/2/2001 and 1/1/2002. The problem is that it is giving me the 7-day average corresponding to the exact day. There is no "minimum over a year" being calculated. Here's how it's written:

SELECT [T3].[SITE_NO], [T3].[DATE], Min(T4.Avg7Day) AS AnnualMinimum
FROM [7_Day_Avg] AS T3 INNER JOIN [7_Day_Avg] AS T4 ON ([T3].[DATE] = [T4].[DATE]) AND (T3.SITE_NO = T4.SITE_NO)
WHERE (([T3].[DATE]>=[T4].[DATE]) And ([T3].[DATE]<=DateAdd("yyyy ",1,[T4].[DATE])))
GROUP BY [T3].[SITE_NO], [T3].[DATE];

Then I need to sort it on 10/1/XXXX, which will give me the minimum 7-day average for 365 days beginning with 10/1 of each year. I'm all out of ideas at this point.
Mar 23 '07 #1
1 1533
nico5038
3,080 Recognized Expert Specialist
To get it per Year use:

SELECT [T3].[SITE_NO], Year([T3].[DATE]), Min(T4.Avg7Day) AS AnnualMinimum
FROM [7_Day_Avg] AS T3 INNER JOIN [7_Day_Avg] AS T4 ON ([T3].[DATE] = [T4].[DATE]) AND (T3.SITE_NO = T4.SITE_NO)
WHERE (([T3].[DATE]>=[T4].[DATE]) And ([T3].[DATE]<=DateAdd("yyyy ",1,[T4].[DATE])))
GROUP BY [T3].[SITE_NO], Year([T3].[DATE]);

Finally the 10/1 requirement (I guess a financial year) can be solved by correcting the [Date] field before using it. When 10/1 is situated in "the next" year, just add 3 months like:

select dateserial(year ([Date]),month([Date])+3,Day([Date]) as FinancialDate.. .

A last tip is to change the Date fieldname into FinancialDate, or another name, as Date is a reserved word and can cause trouble...

Nic;o)
Mar 24 '07 #2

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

Similar topics

1
2082
by: Tristan | last post by:
Im trying to expand a search util by uing regular expression to allow common search criteria such as +-* and phrases "". My understanding of ereg(string pattern, string string, ) is that the array register should collect all instances that match the pattern. Heres is an example of the code: $word4 = "+budgie +ferret dog."; //set phrase
3
2553
by: John J. Walton | last post by:
Hi ! I wonder if anyone can give me some advice. I have been in IT for 30 yrs. Most of the time I have coded in Cobol on medium size systems (Data General, now a dinosaur). For the past 2 years I have coded in a proprietary, object-oriented language called Graphtalk(CSC). I have been studying JAVA and need very much to get into a shop that will allow me to improve and enhance my abilities with JAVA. As we all know, most companies want...
4
5395
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm working on it but not making much progress. Is there any free code available anywhere? I know it...
15
1688
by: JKop | last post by:
I've been searching the Standard for info about the minimum "bits" of the intrinsic types, but haven't been able to find it. Could anyone please point me to it? -JKop
1
2317
by: Kosmos | last post by:
Hi, I really need some help here because I am not a programmer but I took on the task because I'm an intern and wanted to rise up to the challenge...and all that crap...anyways over the past few days I have gotten familiar enough with access to be able to take an excel data sheet into access, cut serial numbers down to their basic numbers so for example if it's MSX19928394Y2K I can cut it down to 19928394 and compare it to the asset number which...
0
1315
by: =?Utf-8?B?VEJR?= | last post by:
We are trying to catalog our internal web services. These have been developed and deployed by different groups over the past several years, and we have no repository of them available - UDDI or otherwise (or this wouldn't have been a question... :-]). There are a couple hundred servers where a web service could have been deployed. Visual Studio will of course show available web services on an individual URL, but in some cases we may...
15
1977
by: rhino | last post by:
I've put together a prototype of two-tiered CSS tabs that works really well in IE6, IE7, and FF2. It also works very well in Opera 9.27 _except_ that the placement of the lower tier of tabs is messed up. Both the XHTML and CSS validate without any errors or warnings. Can anyone help me figure out what is wrong? I'd be especially interested in the technique you used to figure out where the problem was. I still struggle a lot when I try to...
275
12431
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
9714
marktang
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...
0
10600
Oralloy
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...
0
10350
jinu1996
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...
1
7638
isladogs
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...
0
5534
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4311
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
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
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...

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.