select need.*,(case user_class_id when '3' then (select real_name from bussiness_person_info where need.username=bussiness_person_info.username) else (select simple_name from bussiness_enterprise_info where need.username=bussiness_enterprise_info.username) end ) as author_name from bussiness_needs as need ;
通过user_class_id的分类,搜索不一样的表,因为比如发需求,这个用户可能是企业商家,也可能是个人商家。他们的表不一样的,要获取的内容,只有通过user_class_id的区分来获取!
如果通过系统用户还要获取微信的头像和昵称,就更复杂些,如下:
select need.*,weixin_user.nickname,weixin_user.headimgurl,(case user_class_id when '3' then (select real_name from bussiness_person_info where need.username=bussiness_person_info.username) else (select simple_name from bussiness_enterprise_info where need.username=bussiness_enterprise_info.username) end ) as author_name from bussiness_needs as need left join ucenter_member on need.username=ucenter_member.username left join weixin_union_member as un on ucenter_member.id=un.member_id left join weixin_user on un.uid=weixin_user.id;