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 prepared statement in sql?

553


Why we use triggers in mysql?

562


How can triggers be used for the table auditing?

598


Difference between global and parameter variables?

1462


What are all the common sql functions?

569






What are few of the schema objects that are created using PL/SQL?

563


Explain the commit statement.

617


how many groups of data types? : Sql dba

572


What are two statement types in sql?

540


How does cross join work in sql?

537


What does dml mean?

549


What is an inner join sql?

549


what is the command line end user interface - mysql? : Sql dba

507


Is subquery faster than join?

573


What is procedure and function?

520