SELECT u.shopid,i.item_stock,i.item_ctime,
Case
When i.item_stock < 10 then 'Group 0'
when i.item_stock between '10' and '99' then 'Group 1'
when i.item_stock between '100' and '999' then 'Group 2'
when i.item_stock >= 1000 then 'Group 3'
Else 'None'
End as Grouping
FROM [dfgsdfg].[dbo].[user_profile$] as u
join item_profile$ as i
on i.shopid = u.shopid
where (i.item_ctime between '2017-01-01' and '2017-05-31')
This is the result I get after I have tried many queries
But the desired table would be like this
GROUP Number of shops
0 xxx
1 xxx
2 xxx
3 xxx
How do I get a table like this i have tried and finding about this for a while now