Question : Count total record by year, month

I have 2 tables. One that contains a client record with the date it was created and another table that holds information about their travel dates. I need to query all people from the first table that have a starting travel date for a particular year in the other table and then total the travelers and group by month.

I have this but the number are way high.

***********
SELECT year(A.webDate) AS thisYear, month(A.webDate) AS thisMonth, COUNT(*) AS tCount, MIN(I.iDate) AS tripStart FROM application A
      INNER JOIN itinerary I ON A.peopleID = I.peopleID
WHERE (A.clientStatus = 'Active') OR (A.clientStatus = 'Travel Complete')
GROUP BY year(A.webDate), month(A.webDate)
HAVING MIN(I.iDate) BETWEEN #fromDate# AND #toDate#
ORDER by thisYear, thisMonth
***********

Thanks for any help.
Doug

Answer : Count total record by year, month

do you want to count people orjourneys, you're curently counting journeys

this counts people?

SELECT year(A.webDate) AS thisYear
         , month(A.webDate) AS thisMonth
         , COUNT(Distinct A.peopleID) AS tCount
         , MIN(I.iDate) AS tripStart
 FROM application A
 INNER JOIN itinerary I
     ON A.peopleID = I.peopleID
WHERE A.clientStatus in ( 'Active', 'Travel Complete')
   and exists (select peopleid from itinery as x
                      where a.peoplid=x.peoplid
                       and x.idate between #fromDate# AND #toDate#
                   )
GROUP BY year(A.webDate), month(A.webDate)
ORDER by 1, 2
Random Solutions  
 
programming4us programming4us