Dev Shed Forums - MS SQL Development http://forums.devshed.com/ en Sun, 22 Oct 2017 06:38:13 GMT vBulletin 60 http://forums.devshed.com/images/misc/rss.png Dev Shed Forums - MS SQL Development http://forums.devshed.com/ Help with query http://forums.devshed.com/ms-sql-development/979183-help-query-new-post.html Fri, 06 Oct 2017 16:49:14 GMT So I want to get all values summed or averaged by date, I am still getting multiple entries per day and not sure why. Please help!

DECLARE @StartDate DateTime SET @StartDate = '2017-08-01'
DECLARE @EndDate Datetime SET @EndDate = '2017-08-31'

SELECT DISTINCT

pl.PlayerID,
y.FirstName,
y.LastName,
PromotionName,
DateRedeemed,
Offer_Amount,
count(SessionCount) as SessionCount,
sum(LiveMins) as LiveMins,
sum(LobbyMins) as LobbyMins,
sum(CashPlay) as CashPlay,
sum(ChipPlay) as ChipPlay,
avg(BetAvg) as [Avg],
sum(CheckOutAmt) as 'Walk With',
sum(WinLoss) as WinLoss,
sum(TheoLoss) as TheoLoss,
count(NumHands) as NumHands,
Convert(Datetime, LastPlayDate,120) as 'LastPlayDate',
CreateDTM as 'Creation Date-Time'
--CASE WHEN d.PlayerID = 'MISSING' then '0' ELSE 'd.PlayerID' END AS --PlayerID


FROM HotelOffers.dbo.Players pl
--bravotglog.dbo.DailyPitData d


LEFT JOIN bravotglog.dbo.DailyPitData d on d.PlayerID = pl.PlayerID
LEFT JOIN HotelOffers.dbo.Offers o on o.PlayerID = pl.PlayerID
LEFT JOIN hoteloffers.dbo.Promotions p on p.PromoID = o.PromoID
LEFT JOIN HotelOffers.dbo.Players y on pl.PlayerID = y.PlayerID

WHERE DateRedeemed is not null
AND DateRedeemed BETWEEN @startdate and @enddate
AND p.PromoType= '2'






GROUP BY

pl.PlayerID,
y.FirstName,
y.LastName,
PromotionName,
DateRedeemed,
Offer_Amount,
LastPlayDate,
CreateDTM


ORDER BY PlayerID Asc ]]>
MS SQL Development TASmith http://forums.devshed.com/ms-sql-development-95/help-query-979183.html