select ContractNm,RepayType,receivableAmount
 from InterestReceive  pivot 
 (sum(receivableAmount)
  for RepayType in(OnceCharge,OtherCharge))请大家帮忙看看

解决方案 »

  1.   

    select ContractNm,OnceCharge,OtherCharge
     from InterestReceive pivot  
     (sum(receivableAmount)
      for RepayType in(OnceCharge,OtherCharge)) pvt
      

  2.   

    --参考:
    Create Table Salary
    (
    HrName varchar(50),
    Monthly varchar(50),
    Money money
    )--往表中插入数据:
    insert into Salary(HrName,Monthly,[Money]) 
    select '张三','一月','3000' union all
    select '张三','二月','3200' union all
    select '张三','三月','3500' union all
    select '李四','一月','3800' union all
    select '李四','二月','4200' union all
    select '李四','三月','3900' union all
    select '张三','一月','2000'--查看正常的数据:select * from Salary
    /*
    HrName                         Monthly                        Money
    ------------------------------ ------------------------------ ---------------------
    张三                             一月                             3000.00
    张三                             二月                             3200.00
    张三                             三月                             3500.00
    李四                             一月                             3800.00
    李四                             二月                             4200.00
    李四                             三月                             3900.00
    张三                             一月                             2000.00
    */--查看行转列后的数据:select 
    HrName as '姓名',
    [一月],[二月],[三月] 
    from Salary 
    pivot(sum([Money]) for Monthly in ([一月],[二月],[三月])) as pvt--结果:
    /*
    姓名                             一月                    二月                    三月
    ------------------------------ --------------------- --------------------- ---------------------
    李四                             3800.00               4200.00               3900.00
    张三                             5000.00               3200.00               3500.00
    */
      

  3.   

    for RepayType in(OnceCharge,OtherCharge)in里不是具体的值么?for RepayType in('OnceCharge','OtherCharge')???