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 / apoorva garg

cityno cityname mails
1 BANGALORE 8KM
2 HSR LAYOUT 20KM
3 MEJISTIC 30KM
4 JAYADEVA 55KM
5 ITPL 80KM
6 HEBBAL 115KM

create table city(name varchar2(10), miles number);
insert into city values('bangalore',8)
insert into city values('hsr',20)
insert into city values('majestic',30)
insert into city values('jayadeva',55)
insert into city values('itpl',80)
insert into city values('hebbal',115)

DISTANCE NO.OFCITY
0-50KM 3
51-100KM 2
101-150KM 4


select * from city


select count(miles),miles
from
(select name,
CASE
WHEN (miles>=0 and miles <=50) THEN '0-50KM '
WHEN (miles>=51 and miles <=100) THEN '51-100KM '
WHEN (miles>=101 and miles <=150) THEN '101-151KM '
END miles
from city)

group by miles

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can a view be mutating? If yes, then how?

582


what is the difference between sql and t-sql? : Transact sql

607


What is offset and limit in sql?

555


how to check myisam tables for errors? : Sql dba

608


What are reports usually used for?

569






what are the different type of normalization? : Sql dba

557


What is bulk compiling in pl/sql.?

613


What are the 3 modes of parameter?

686


How run sql*plus commands that are stored in a local file?

526


What is a sql*loader control file?

622


How do I view tables in sql developer?

518


What is indexing in sql and its types?

547


How to get list of all tables from a database?

632


What is the unique index?

529


What is pl sql in dbms?

508