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

enter image description here

i want follow

enter image description here

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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -