I'm trying to get the output as follows but don't understand how can I put all the conditions and get different counts accordingly:
Below Output is getting right now without condition:
Below is my table data:
Below is my Query:
SELECT COUNT(usd.user_name) AS All_User,
ROUND((ROUND((SUM(usd.FREE_UPLOAD_OCTETS)/1048576)))/1024,2) ROUND((ROUND((SUM(usd.FREE_DOWNLOAD_OCTETS)/1048576)))/1024,2) AS Total_Usage
FROM user_session_detail usd
WHERE usd.SESSION_START_TIME > '2022-02-01 00.00.01' AND usd.SESSION_START_TIME < '2022-02-01 03.59.59'
CodePudding user response:
you can use group by case when condition < 101 then 1 when condition < 301 then 2 when condition < 501 then 3 when condition < 801 then 4 else 5 end
at the end
CodePudding user response:
Something like this should work
Select conditions, sum(total_users) as users, sum(total_usage) as usage from(
SELECT total_users, total_usage,
case
when total_usage < 100 then 'less then 100'
when total_usage > 100 then 'more then 100'
else null
end as conditions
from user_session_detail
) b group by conditions