USing Min/Max with conditional operator

Posted by user638501 on Stack Overflow See other posts from Stack Overflow or by user638501
Published on 2011-02-28T23:16:45Z Indexed on 2011/02/28 23:25 UTC
Read the original article Hit count: 262

Filed under:

Hello All,

I am trying to run a query to find max and min values, and then use a conditional operator. however when I try to run the following query, it gives me error - "misuse of aggregate: min()".

My query is:

SELECT a.prim_id, min(b.new_len*36) as min_new_len, max(b.new_len*36) as max_new_len
FROM tb_first a, tb_second b
WHERE a.sec_id = b.sec_id AND min_new_len > 1900 AND max_new_len < 75000
GROUP BY a.prim_id
ORDER BY avg(b.new_len*36);

Any suggestions ?

© Stack Overflow or respective owner

Related posts about sql