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 / prativa mishra

select range distance,count(range) no_of_city
from
(SELECT cityname,mails,
CASE WHEN MAILS BETWEEN 0 AND 50 THEN '0-50'
WHEN MAILS BETWEEN 51 AND 100 THEN '51-100'
ELSE '101-150'
END RANGE
FROM CITY1)
group by range

Is This Answer Correct ?    20 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is bulk compiling in pl/sql.?

600


Explain spool.

673


What is offset in sql query?

584


explain advantages of innodb over myisam. : Sql dba

632


How to Execute a Package in PL/SQL.?

570






What are different types of statements supported by sql?

596


What is pessimistic concurrency control? : Transact sql

572


How do I find duplicates in two columns?

540


Why use subqueries instead of joins?

590


How would you pass hints to the sql processor?

517


What are the most important ddl statements in sql?

563


how to drop an existing index in mysql? : Sql dba

527


Which table is left in left join?

505


How to select all records from the table?

595


Is trigger a stored procedure?

493