0

Store No Store Name Region Division Q10(response) Q21(response)

2345       ABC              North Test              1                       5
2345                            North Test              6                       3
2345       ABC              North Test              4                       6

1st calculation

1 ) Engaged(%) = Response Greater than 4.5
3 (total response greater than 4.5) / 6 (total count) * 100 = 50%

Store No Store Name Region Division Q10 Q21
2345             ABC      North Test           1       5
2345             ABC      North Test           6       3
2345            ABC       North Test           4       6

2) not engaged (%) = Response less than 2
1 (total response less than 2) / 6 (total count) * 100 = 16.66%

I should be able to get the table like this

Store No Store Name Region Division Engaged(%) Disengaged(%)
2345            ABC     North Test                 50                 16.66

1 Answer 1

2

Your statistics rounded 2 digits after point (T-SQL), grouped by stores:

SELECT
    store_no,
    store_name,
    region,
    division,
    ROUND( CAST( (SUM(CASE WHEN q10 > 4.5 THEN 1 ELSE 0 END) + SUM(CASE WHEN q21 > 4.5 THEN 1 ELSE 0 END)) AS FLOAT) / (COUNT(q10)+COUNT(q21)) * 100, 2)   AS engaged,
    ROUND( CAST( (SUM(CASE WHEN q10 < 2 THEN 1 ELSE 0 END) + SUM(CASE WHEN q21 < 2 THEN 1 ELSE 0 END)) AS FLOAT) / (COUNT(q10)+COUNT(q21)) * 100, 2)  AS not_engaged
FROM
    yourtable
GROUP BY
    store_no,
    store_name,
    region,
    division
Sign up to request clarification or add additional context in comments.

1 Comment

+1 That should do it. Note on COUNT(*)*2 - it ignores NULLs; if these need to be handled better write it as COUNT(q10)+COUNT(q21)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.