I need to group by ranges this is the result where I want to get
The query I am using is the following:
SELECT org_account, COUNT(RESULT) AS TOTAL_MT
FROM TABLE
WHERE FECHA = '02/12/2018' AND mt_msc_addr IS NOT NULL
GROUP BY org_account
ORDER BY TOTAL_MT DESC
The result of the query is as follows:
ORG_ACCOUNT TOTAL
Gateway_G 34
WSMS 23
smsgw 23
VMSTRWI 22
sdp 22
OtaDMC 18
ocs 17
PcRf 15
MNP_icon 3
wapgw 1
We can use your query as the basis for everything we do to add that new column.
Since it doesn't exist, we can't add it directly to your query.
Let's call your query A* (that means that every time you read that, your whole query should be as it is now)
But we could do a union for example to generate the output:
Note that you have to complete it where the ellipses are.
Also, we could use a case
Where you would also have to complete the ellipses.
All this would be easier, if your ranges were already defined in another table, and you would only adjust them using a join. But since you say that your table does not have an id, it would be more complex..
Although the recommendation would be to create a table
And then with that, you would just do a join between your query and this table like this:
basically in your same question you are answering, I show you:
SELECT org_account, COUNT(RESULT) AS TOTAL_MT FROM TABLE WHERE FECHA = '02/12/2018' AND mt_msc_addr IS NOT NULL GROUP BY org_account HAVING COUNT(RESULT) BETWEEN 15 AND 23 ORDER BY TOTAL_MT DESC
note: I couldn't see your image, so with the first comments I think I understood, I hope it helps you...