how can i remove null section and combine into one in mysql? -
select a_name, round(case when m_type_code = 001 avg(a_price) end) a, round(case when m_type_code = 002 avg(a_price) end) b price group a_name, m_type_code;
when use result is
a_name ㅣ ㅣ b ㅣ apple ㅣ(null) ㅣ 3313 ㅣ apple ㅣ 3000 ㅣ (null) ㅣ grape ㅣ(null) ㅣ 5020 ㅣ grape ㅣ 3140 ㅣ (null) ㅣ ...
so thought group a_name one, instead ii came out 2 different row null how can remove null , combine one?
not sure if avg , coalese give desired results though.
select a_name , round(avg(case when m_type_code = '001' coalesce(a_price,0) end)) , round(avg(case when m_type_code = '002' coalesce(a_price,0) end)) b price group a_name;
or maybe depending on you're trying accomplish avg.
select a_name , round(avg(case when m_type_code = '001' a_price end)) , round(avg(case when m_type_code = '002' a_price end)) b price group a_name;
Comments
Post a Comment