Wednesday, 15 June 2011

sql - How to print a MAX and a description from Java Database -



sql - How to print a MAX and a description from Java Database -

i'm origin larn connecting databases via java programs. have table called city, contains 2 columns: cityname , population. want find highest population, , give population along name of corresponding city.

i know how highest population (see following, know not ideal @ to the lowest degree working me):

double max = 0.0; string sqlstatement = "select max(population) city"; resultset result = stmt.executequery(sqlstatement); if (result.next()) { highest = result.getdouble(1); } system.out.printf("highest population: %,.0f", highest);

i pretty sure highest population plus name of corresponding city, sql statement should eb changed :

"select cityname, max(population) city grouping cityname";

but can't work beyond that. thought add together

string highestcity = result.getstring(2)

and add together highestcity system.out.printf output line, isn't working.

can help?

thanks!

how ?

string sqlstatement = "select cityname, population city population in (select max(population) city)";

java sql

No comments:

Post a Comment