select b.* , cout_of_rows, max_rows from (select count(*) as count_of_rows, max(c_level) as max_rows from ch_st where active = 1 and a_id = 99999) a, ch_st b where a.c_level = b.c_level and a.active=1 and b.a_id = 99999 ?? On Thu, 20 Jan 2005 11:09:33 -0800 (PST), David <thump@xxxxxxxxxxxxxxxx> wrote: > How can I accomplish the following...the problem is a bit beyond my SQL > skills: > > select > a_id, > c_name, > c_id, > c_level, > e_d, > t_c, > t_l, > a_s, > g_t, > s_x, > s_x, > c_a, > t_cd, > c_a, > n_k > from ch_st c > where > active = 1 > and c.a_id = 99999 > > Based on two conditions(active and a_id =), the select will return 1 or > more rows. > > The final output should list the columns in the select above, BUT only 1 > row should be outpouted and that row should list a count of the number of > rows matching the criteria and the max c_level in the rows returned and > the associated columns. > > So, simple query above returns say 4 rows....final query should return 1 > row and perform a count and a max on a column and only list the columns > associated with that max value... > > I hope that makes sense...I know max, group_by, etc are in the mix, but... > > LOL > ;) > -- > .. > David > > -- > //www.freelists.org/webpage/oracle-l > -- //www.freelists.org/webpage/oracle-l