Question : sql select with group by and conditions

Hi all,

the table has year, month, day, hour, min and X cols, all numeric.

I need to select
1. number of X values per each or particular year
2. number of X values per each or particular month in a given year
3. If in the year 1900 in month 1 the X was recorded on the 4th, 5th, 12th and 23rd days,
    I need a select statement that gives me all the years that same distribution of X happened on the same month 1

It's a mouthful, I apologize, more than willing to give additional points...

Thank you.

Answer : sql select with group by and conditions

OK, this seems to be working for the third task.  To test it, open the attached MDB, open the form frmFindSimilar, and enter parameters for year and month.

For example, for April (month 4) 1975, the only similar year is 1994.

There is no similar year for the current month 2010, 8, but there are for last month (2010, 7 returns 1733 and 1752) and next month (2010, 9 returns 1790 and 1991).

The form relies on the queries qryBasePeriod and qrySimilarPeriods (SQL statements below).
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
SQL for qryBasePeriod

SELECT phases_uude.X, phases_uude.iYEAR, phases_uude.iMONTH, phases_uude.iDAY
FROM phases_uude
WHERE (((phases_uude.iYEAR)=[Forms]![frmFindSimilar]![txtYear]) AND ((phases_uude.iMONTH)=[Forms]![frmFindSimilar]![txtMonth]));

SQL for qrySimilarPeriods

SELECT phases_uude.iYEAR
FROM phases_uude INNER JOIN qryBasePeriod ON (phases_uude.X=qryBasePeriod.X) AND (phases_uude.iMONTH=qryBasePeriod.iMONTH) AND (phases_uude.iDAY=qryBasePeriod.iDAY)
WHERE phases_uude.iYEAR<>qryBasePeriod!iYEAR
GROUP BY phases_uude.iYEAR
HAVING Count(phases_uude.X)=DCount("1","qryBasePeriod")
ORDER BY phases_uude.iYEAR;
 
 
Random Solutions  
 
programming4us programming4us