March 25, 2018 at 11:16 am
Hello guys i need a little help. How i can count one column when i have two statements when is 1 and 2 for AS_TYP. Which this script do for Statement 1, but need and for statement 2.Should i have to use UNION ALL to write the same with Statement 2 but i think group by and having can't move to the end of script i dont know.Thanks
SELECT acs.UID as AccountID ,
acc.AC_UNM AS UserName,
COUNT(acs..AS_TYP) AS Deposits,
SUM(acs.AMT) AS DepositAmount,
SUM(acs.BNS) AS BonusAmount,
CC.Name
FROM AccountStatement as acs
JOIN Accounts AS acc ON acc.ID=ACS.UID
JOIN ConfigCurrencies AS cc ON acs.CUR = CC.ID
WHERE acs.AS_TYP = 1 AND
acc.SiteID = 34 AND
acc.LastLoginDate > '20180101' AND
acc.LastLoginDate < '20180131'
GROUP BY acs.UID,acc.AC_UNM,CC.Name
HAVING COUNT(acs.AS_TYP) >= 1
ORDER BY COUNT(acs.AS_TYP) DESC
March 25, 2018 at 11:46 am
Founded solution
CREATE TABLE #TempTable(
UserID int,
Withdrw int
)
INSERT INTO #TempTable(UserID,Withdrw)
SELECT UID,
COUNT(AS_TYP) AS AS_tYP
FROM AccountStatement
WHERE AS_TYP = 2
GROUP BY UID
HAVING COUNT(AS_TYP) >= 1
ORDER BY COUNT(AS_TYP) DESC
And join with main script.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply