sql - Column to be filled based on condition -
i have following data
prod_no prod_cat prod_description x23 pens n/a x23 pencil in warehouse x23 ink " x30 books " x30 drawings not in warehouse x30 erasers " what achieve if prod_description having n/a or ", rows filled comments exist prod_no. e.g. x23 in warehouse filled rows. x30 not in warehouse filled rows.
prod_no prod_cat prod_description x23 pens in warehouse x23 pencil in warehouse x23 ink in warehouse x30 books not in warehouse x30 drawings not in warehouse x30 erasers not in warehouse how can this? there many prod_no , prod_description varies each prod_no
you should make join table maximum prod_description each prod_no , use decode output value null,'' or 'n/a':
select t.prod_no, t.prod_cat, decode (t.prod_description, null,tmax.prod_desc_max, '',tmax.prod_desc_max, 'n/a',tmax.prod_desc_max, t.prod_description) prod_description t left join (select prod_no, max(prod_description) prod_desc_max t group prod_no) tmax on t.prod_no = tmax.prod_no
Comments
Post a Comment