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

pls give me answer. i want urgent

Answer Posted / senthil

hi,
if mails field is numeric above query is correct but mails filed is varchar that is contain 'km' so test my query....
Ex:
select RANGE distance,count(range) no_of_city
from
(SELECT citiname,mails,
CASE WHEN to_number(substr(mails,0,(instr(mails,'k')-1))) BETWEEN 0 AND 50 THEN '0-50'
WHEN to_number(substr(mails,0,(instr(mails,'k')-1))) BETWEEN 51 AND 100 THEN '51-100'
ELSE '101-150'
END RANGE
FROM test1) group by range

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How does one use sql*loader to load images, sound clips and documents? : aql loader

677


What is the life of an sql statement?

527


Why are cursors used?

585


How do I truncate a word?

530


What is meant by <> in sql?

511






how many tables will create when we create table, what are they? : Sql dba

549


Can sql function call stored procedure?

562


Explain the uses of control file.

618


What is an escape character in sql?

567


What is asqueryable?

534


What are the advantages of sql? Explain

652


What is replication id?

524


Are ddl triggers fired for ddl statements within a pl/sql code executed using the dbms.sql package?

626


What is sqlexception in java?

553


What are the different ways to optimize a sql query?

492