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 / js

SELECT R,COUNT(R) FROM
(
SELECT cityname,mail,
CASE WHEN SUBSTR(MAIL,1,INSTR(MAIL,'KM' )-1) BETWEEN 0 AND 50 THEN '0-50'
WHEN SUBSTR(MAIL,1,INSTR(MAIL,'KM' )-1) BETWEEN 51 AND 100 THEN '51-100'
ELSE '101-150' END R FROM CITY) GROUP BY R;

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which join is like inner join?

559


How do you rename a table in sql?

532


how are mysql timestamps seen to a user? : Sql dba

561


Can you select everything, but 1 or 2 fields, without writer's cramp?

495


What are the two types of periodical indexes?

503






Can we use threading in pl/sql?

514


Explain select statements in sql?

584


what are date and time functions in mysql? : Sql dba

530


What mean sql?

576


What is trigger in sql?

576


What is the maximum number of rows in sql table?

543


write an sql query to find names of employee start with 'a'? : Sql dba

575


What problem one might face while writing log information to a data-base table in pl/sql?

552


what are the different index configurations a table can have? : Sql dba

566


what is 'mysqlimport'? : Sql dba

570