I'm trying to write a query to find out how many customers I have per fixed period of time. The periods are already set in the DB and I'm simply running a sum on the customers in that period.

Using:

```
select distinct numguests, checknum
from guest_check_hist
where revenuecenterid in ('146708') and openfixedperiod = '89'
    and openbusinessdate between dateAdd(day, -2,getDate()) and dateAdd(day, -1,getDate())`

```

I find that I had 7 orders totaling 10 customers.

I then run:

```
Select Distinct MENU_ITEM_FIXED_PERIOD_TOTAL.businessDate as 'Effective Date',
    sum(H.guests) as guests, menu_item_fixed_period_total.fixedperiod,
    menu_item_fixed_period_total.revenuecenterid
FROM MENU_ITEM_FIXED_PERIOD_TOTAL
inner JOIN (
    select distinct checknum, numguests as guests, openbusinessdate, revenuecenterid, openfixedperiod 
    from guest_check_hist
    where openbusinessdate between dateAdd(day, -2,getDate()) and dateAdd(day, -1,getDate())
) H ON Menu_item_fixed_period_total.businessdate = H.openbusinessdate and menu_item_fixed_period_total.revenuecenterid = H.revenuecenterid and H.openfixedperiod = menu_item_fixed_period_total.fixedperiod
where menu_item_fixed_period_total.revenuecenterid in ('146708')
    and menu_item_fixed_period_total.businessdate between dateAdd(day, -2,getDate()) and
    dateAdd(day, -1,getDate()) and fixedperiod = '89'
group by fixedperiod, businessdate, menu_item_fixed_period_total.revenuecenterid
order by fixedperiod`

```

and find that I had 200 guests.

Obviously this isn't right.

Numguests is of datatype Int. Can you point me in the right direction on where my error is?

Actual Data:

Individual Orders:

* numguets checknum
* 0, 2917
* 1, 2918
* 1, 2921
* 1, 2922
* 2, 2919
* 2, 2923
* 3, 2920

Summed Results:

* [Effective Date] guests fixedperiod revenuecenterid
* 2014-1-20, 200, 89, 146708

Expected Results:

* [Effective Date] guests fixedperiod revenuecenterid
* 2014-1-20, 10, 89, 146708