mysql      
                  select
            *
        from
            mr_user_info u,mr_visit_info f,
            (
                select
                    case
                when v.relation_type = 2 then
                    (
                        select io.visit_id from mr_visit_info io,mr_item_info_fb aa where io.relation_id = aa.item_id and aa.org_id = '001' and v.visit_id = io.visit_id
                    )
when v.relation_type = 1 then
                    (select vq.visit_id from mr_beauty_org_info_fb bof,mr_visit_info vq where vq.relation_id = bof.org_id and bof.org_id = '001')
            when v.relation_type = 3 then
            (select vq.visit_id from mr_visit_info vq,mr_doc_info_fb doc where doc.org_id = '001' and doc.doc_id = vq.relation_id)
                end vid,
case 
                    when v.relation_type = 1 then
                    (select
                    fb.org_name
                    from
                    bione_org_info fb,mr_visit_info v,mr_beauty_org_info_fb bp
                    where
                    v.relation_id = bp.org_id and fb.org_no = bp.org_id and bp.org_id = '001'
                    )
                    when v.relation_type = 2 then
        (
        select
        i.item_name
        from
        mr_item_info_fb i,mr_visit_info v
        where
        v.relation_id = i.item_id and i.org_id = '001'
        )
                    when v.relation_type = 3 then
        (
        select
        b.true_name
        from
        mr_doc_info_fb b,mr_visit_info v
        where
        v.relation_id = b.doc_id and b.org_id = '001'
        )
                    end visitname
            from
                mr_visit_info v
            ) ff
where
            ff.vid = f.visit_id
            and f.user_id = u.user_id
        and f.relation_id  != '0'
   
 
   