I am creating a bucket on whether insurance was reported or not for my database.table per booking.
What i want to do is get a cound per userid where insurance reported is yes and a count per userid when insurance = no and then group by bmm, byyyy, dmm, dyyyy
it sounds simple but i think the bucket is confusing me
SELECT CASE WHEN [insreported] IS NULL THEN 'NO' WHEN [insreported] = 'YES' THEN 'YES' END AS BUCKET, USERID, BMM, BYYYY, DMM, DYYYY
FROM (SELECT BOOKNO, USERID, INSREPORTED, BMM, BYYYY, DMM, DYYYY
FROM dbo.agent_insurance_incentive_data) AS derivedtbl_1
You’re probably looking for something like this.
The inner query counts the number of reported/not reported per user and BMM, BYYYY, DMM, DYYYY. The outer query sums this by user. I’m not quite sure what your goal is, but here this could be rewritten as just the outer query since the summation will be the same.