I Have A Table Like This.

Cityno Cityname Mails
1 Bangalore 8km
2 Hsr Layout 20km
3 Mejistic 30km
4 Jayadeva 55km
5 Itpl 80km
6 Hebbal 115km

I Have Data Like This

I Want O/p Like This
Distance No.ofcity
0-50km 3
51-100km 2
101-150km 4

And So On

Answer Posted / kavitha nedigunta

SELECT DISTANCE,COUNT(*) NO_OFCITY
from
(SELECT (CASE WHEN TO_NUMBER(RTRIM(MAILS,'KM')) BETWEEN 0
AND 50 THEN '0-50'
WHEN TO_NUMBER(RTRIM(MAILS,'KM')) BETWEEN 51 AND
100 THEN '51-100'
ELSE '101-150' END) DISTANCE
FROM TEST001) A
GROUP BY DISTANCE
order by to_number(replace(DISTANCE,'-',''))

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is the functionality of the function htmlentities? : Sql dba

512


what are all the different types of indexes? : Sql dba

522


In what condition is it good to disable a trigger?

546


What is the least restrictive isolation level? : Transact sql

558


Why is a trigger used?

519






What is normalization in a database?

601


Does postgresql run on the cloud?

580


What is the difference between join and natural join?

465


what are all different types of collation sensitivity? : Sql dba

515


Is sqlite thread safe?

595


What are the methods of filing?

513


How do you modify a table in sql?

553


What are sql functions? Describe in brief different types of sql functions?

480


What is oracle and pl sql?

655


Explain the components of sql?

583