You can write query based on another query. So, if the actual query does
what it should do, keep it unmodified and write ANOTHER query:
Bring your actual query TWICE in the new query, one will get an _1 appendto
its name.
Change the query to a Total query.
Drag the ENERTIA_NO (probably what was your 'id' field, I assume, in the
first query), and D_DATE field from the not _1 query into the grid, keep
the proposed GROUP BY.
Drag D_DATE from the not _1 query a second time, change the GROUP BY to
WHERE, and, in the criteria:
>= [queryName_1].D_DATE
( use the real query name, with its _1 at the end of
the name)
Link the two queries, in the upper part of the query designer, by dragging
the ENERTIA_NO from one of them and dropping it on the same field of the
other query. A black line will now link the two queries.
In the grid, a new column, type:
COUNT(*)
and change the GROUP BY to EXPRESSION.
That's all.
That still assumes that ENERTIA_NO is such that sequentially un-interrupted
dates share the same value in that ENERTIA_NO.
Vanderghast, Access MVP
SELECT idDateProd.id, idDateProd.date, idDateProd.production, COUNT(*)
FROM idDateProd INNER JOIN idDateProd AS idDateProd_1 ON idDateProd.id =
idDateProd_1.id
WHERE idDateProd.date >= idDateProd_1.date
GROUP BY idDateProd.id, idDateProd.date, idDateProd.production;
should do, as long as your 'id' match the group of sequential days.
I also assumed the first three columns were known, and that you were
looking
for the fourth one.
My current SQL is listed below. I would like to count the D_DATE
(where the first date is 1 and so on to time zero the data), grouping
by ENERTIA_NO. I apologize for the confusion, but I'm not very
familiar with the SQL format in Access. How can I modify this code to
include what you showed above?
SELECT dbo_AC_DAILY.PROPNUM, dbo_AC_PROPERTY.ENERTIA_NO,
dbo_AC_PROPERTY.MAP_QUAD, dbo_AC_PROPERTY.RESERVOIR,
dbo_AC_PROPERTY.SPUD_DATE, dbo_AC_PROPERTY.TIL_DATE,
dbo_AC_DAILY.D_DATE, dbo_AC_DAILY.GAS INTO WHOLE_KY_Hz_From2000
FROM (dbo_AC_DAILY INNER JOIN dbo_AC_PRODUCT ON dbo_AC_DAILY.PROPNUM =
dbo_AC_PRODUCT.PROPNUM) INNER JOIN dbo_AC_PROPERTY ON
dbo_AC_PRODUCT.PROPNUM = dbo_AC_PROPERTY.PROPNUM
WHERE (((dbo_AC_DAILY.D_DATE)>[SPUD_DATE]) AND
((dbo_AC_PROPERTY.WELLCLASS)="hor") AND ((dbo_AC_PROPERTY.STATE)="ky")
AND ((dbo_AC_PROPERTY.SPUD_DATE)>#1/1/2000#))
GROUP BY dbo_AC_DAILY.PROPNUM, dbo_AC_PROPERTY.ENERTIA_NO,
dbo_AC_PROPERTY.MAP_QUAD, dbo_AC_PROPERTY.RESERVOIR,
dbo_AC_PROPERTY.SPUD_DATE, dbo_AC_PROPERTY.TIL_DATE,
dbo_AC_DAILY.D_DATE, dbo_AC_DAILY.GAS
ORDER BY dbo_AC_PROPERTY.ENERTIA_NO, dbo_AC_PROPERTY.MAP_QUAD,
dbo_AC_PROPERTY.RESERVOIR;