How use MAX in mysql to get follow result -
this query
select research_id, if(product_id = 4, if(value regexp '^-?[0-9]+$' > 0, value, if(value = 'yes', 1, 0)), 0) val1, if(product_id = 8, if(value regexp '^-?[0-9]+$' > 0, value, if(value = 'yes', 1, 0)), 0) val2 research_product_details rpd left join products p on rpd.product_id = p.id (product_id = 4 , value >= 50) or (product_id = 8 , value >= 50) order research_id asc , product_id asc
and got result query
i want follow
as @jkike mentioned in comment, 1 way achieve want wrap current query , group by
research_id
column, selecting max value val1
, val2
columns:
select t.research_id research_id, max(t.val1) val1, max(t.val2) val2 ( select research_id, if(product_id = 4, if(value regexp '^-?[0-9]+$' > 0, value, if(value = 'yes', 1, 0)), 0) val1, if(product_id = 8, if(value regexp '^-?[0-9]+$' > 0, value, if(value = 'yes', 1, 0)), 0) val2 research_product_details rpd left join products p on rpd.product_id = p.id (product_id = 4 , value >= 50) or (product_id = 8 , value >= 50) order research_id asc , product_id asc ) t group t.research_id
Comments
Post a Comment