表 E_MEMBER 有如下2个字段:
ISVISIT 有2种状态:A和B
VISITCOST :费用想通过一条SQL语句查询出来如下显示===================================
 A 状态下需求费用||  B状态下需求费用
====================================求大神,在线等,很捉急。

解决方案 »

  1.   

    select case when isvisit = 'A' then visitcost else 0 end as 'A 状态下需求费用',
    case when isvisit = 'B' then visitcost else 0 end as 'B 状态下需求费用'
    from e_member
      

  2.   

    大大,我想延伸一下。
    还有一个表 E_GROUPS ,E_GROUPS 和E_MEMBER 通过 GROUPSNO关联。
    我想查出E_GROUPS 表的GROUPSNAME,求指教。 
      

  3.   

    +1  select ISVISIT,VISITCOST,mid=identity(int,1,1) into #tmp from E_MEMBER
    --select * from #tmp
    select 
        [A需求费用]=max(case when [ISVISIT]='A' then [VISITCOST] else 0 end),
        [B需求费用]=max(case when [ISVISIT]='B' then [VISITCOST] else 0 end)from 
        #tmp 
    group by midGOdrop table #tmp