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

In a distributed database system, can we execute two queries simultaneously?

567


Can two tables have same primary key?

531


Why is there a need for sqlcode and sqlerrm variables?

585


how many columns can be used for creating index? : Sql dba

515


Explain correlated query work?

589






How do I find duplicates in sql?

503


- Types of triggers - View - Dcl - Procedures, packages, functions - Metasolve - Can use Dcl in triggers - package case study - Cursor and its types - triggers schedule - Wrap - Why we are using fetch and for in cursor. difference?

1384


what is the difference between inner and outer join? Explain with example. : Sql dba

546


Why is sql*loader direct path so fast?

595


Explain the difference between rename and alias?

543


What are the advantages of stored procedure?

540


Why coalesce is used in sql?

469


How insert into statements in sql?

586


what's the difference between a primary key and a unique key? : Sql dba

504


Why procedure is used in sql?

530