其实这个从表设计的角度来考虑的话就很容易,你只要把phone_type定义为number型或char型的,填入数字 0,1,2,3,4等,按照优先级来设定对应mobile,office等
这样select phone_number from (select rownum as rn,phone_num from phone where cif_num='' order by phone_type asc) where rn=1就可以查到tel了
fax类似
如果你的type都为英文moblie等的话,就比较复杂,个人认为应该考虑用行转列实现。
仅作参考
这样select phone_number from (select rownum as rn,phone_num from phone where cif_num='' order by phone_type asc) where rn=1就可以查到tel了
fax类似
如果你的type都为英文moblie等的话,就比较复杂,个人认为应该考虑用行转列实现。
仅作参考
rownum as rn,rownum是oracle里查询时的行号,order by type asc的话,第一行就必然是优先级最高的,所以取第一行的作为tel就可以了。
1,表横放,转换成这样个结构:
客户名,Mobile,teloffice,telhome,faxoffice,faxhome
2,用decode函数来得到你想要的tel和fax
你的方法应该可以 使用decode(phone_type,'MB',100,'OT','10','HT',1) rn 这样就可以设定对应的优先级了,然后select max(...)谢谢大家!!!