SRK Posted September 15, 2020 Share Posted September 15, 2020 Hi all, Newbie to the forum and the world of SQL, hence apologies for my naivety. From the attached table, I'm trying to create a range (as an output) and create a summary as shown in the attached in yellow. The reason being, the size of raw data (+2m rows). Trying to do this ins Microsoft SQL Management Studio. Any help would be greatly appreciated. Thank you. SQL.xlsx Link to comment Share on other sites More sharing options...
shaili_shah Posted September 25, 2020 Share Posted September 25, 2020 I've written the query plz refer it. select t.order_count as [score range], count(*) as [number of occurrences] from ( select case when order_amount between 50 and 100 then ' 50 - 100 ' when order_amount between 101 and 150 then ' 101 - 150 ' when order_amount between 151 and 200 then ' 151 - 200 ' when order_amount between 201 and 250 then ' 201 - 250 ' when order_amount between 251 and 300 then ' 251 - 300 ' else ' 300+ ' end as order_count from order) t group by t.order_count order by count(*) . I hope you get the output you want. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now