grecorromano Posted June 7, 2010 Share Posted June 7, 2010 Hi im trying to get the highest count of a row. here is what i'm doing:SELECT MAX(Y),X FROM(SELECT Pe.nombreArtistico AS X,COUNT(Po.id) AS YFROM Pelicula P, Persona Pe, Postulada Po, Premio Pr, TABLE(Pr.nombre) C, PERSONA_ROL_PELICULA PRP WHERE P.id=PRP.id_pelicula AND Pr.id=Po.id_premio AND PRP.id_postulada=Po.id AND Pe.id=PRP.id_persona AND Po.ganadora='si' AND C.nombre='Mejor Director' GROUP BY Pe.nombreArtistico ORDER BY COUNT(Po.id) DESC)GROUP BY X;but the output is:4 John Ford3 William Wylerit should be just:4 John Fordi'm using oracle. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 7, 2010 Share Posted June 7, 2010 It's going to select the max Y for each X. If you only want the highest Y, order by max Y and use limit to only get one row. Link to comment Share on other sites More sharing options...
grecorromano Posted June 7, 2010 Author Share Posted June 7, 2010 ok, but if i have more than one people with 4.For exaple, if i have more than one people with 4 i want it to show:4 John Ford4 George Smith4 Mary Falcoetc. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 7, 2010 Share Posted June 7, 2010 In that case you need a WHERE clause, where you tell it to only return rows where Y is MAX(Y). Link to comment Share on other sites More sharing options...
grecorromano Posted June 7, 2010 Author Share Posted June 7, 2010 Group functions are not allowed in WHERE clause Link to comment Share on other sites More sharing options...
justsomeguy Posted June 7, 2010 Share Posted June 7, 2010 You could have a subquery, e.g. WHERE Y IN (SELECT MAX(Y) FROM table). It might also be easier to process that with another language, so get the results ordered by Y and keep printing them until you find one that is less than the max. Link to comment Share on other sites More sharing options...
grecorromano Posted June 8, 2010 Author Share Posted June 8, 2010 i tryed this and it worked:SELECT Y,X FROM(SELECT Pe.nombreArtistico AS X,COUNT(Po.id) AS Y FROM Pelicula P, Persona Pe, Postulada Po, Premio Pr, TABLE(Pr.nombre) C, PERSONA_ROL_PELICULA PRP WHERE P.id=PRP.id_pelicula AND Pr.id=Po.id_premio AND PRP.id_postulada=Po.id AND Pe.id=PRP.id_persona AND Po.ganadora='si' AND C.nombre='Mejor Director' GROUP BY Pe.nombreArtistico ) WHERE Y=(SELECT MAX(Z) FROM (SELECT COUNT(Po.id) AS Z FROM Pelicula P, Persona Pe, Postulada Po, Premio Pr, TABLE(Pr.nombre) C, PERSONA_ROL_PELICULA PRP WHERE P.id=PRP.id_pelicula AND Pr.id=Po.id_premio AND PRP.id_postulada=Po.id AND Pe.id=PRP.id_persona AND Po.ganadora='si' AND C.nombre='Mejor Director' GROUP BY Pe.nombreArtistico ));thanks for the ideas, i've been working on this all day long! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.