我有一张表tb_phone
和
person_number home_number mobile_number work_number
1 34646 989938377 9800
2 83837 981083737 890
3 64746 982726666 8373
我的phone_type是' W'如果work_number在那里并且' M'如果手机号码不为空并且' H'如果家不是空的
person_number PHONE_number phone_type
1 34646 H
1 989938377 M
1 9800 W
2 83837 H
2 981083737 M
2 890 W
这可以通过任何查询吗?
答案 0 :(得分:1)
执行UNION ALL
,每种数字类型都有一个选择:
select person_number, home_number as PHONE_number, 'H' from tb_phone
UNION ALL
select person_number, mobile_number, 'M' from tb_phone
UNION ALL
select person_number, work_number, 'W' from tb_phone
也许你想为每个选择添加WHERE xyz_number is not null
以避免空数?