select chargedeptId ,itemname ,count(itemname)as itemnamenum, sum(TotalPrice) as totalprice ,systype,chargeId,payer,UnitPrice,TotalPrice ,invoiceno from vw_HC_getChargeItem  where systype=2 Group by chargeId

解决方案 »

  1.   

    select chargedeptId ,itemname ,count(itemname)as itemnamenum, sum(TotalPrice) as totalprice ,systype,chargeId,payer,
    UnitPrice,TotalPrice ,invoiceno from vw_HC_getChargeItem  where systype=2 Group by chargedeptId,itemname
      

  2.   

    select chargedeptId ,itemname ,count(itemname)as itemnamenum, sum(TotalPrice) as totalprice ,systype,chargeId,payer,UnitPrice,TotalPrice ,invoiceno 
    from vw_HC_getChargeItem  where systype=2 Group by chargeId,itemname,systype,chargeId,payer,UnitPrice,TotalPrice ,invoiceno
      

  3.   

    --刚才没看全,楼主应该是这个意思。
    select chargedeptId ,itemname ,(select count(1) from vw_HC_getChargeItem where systype=2 and chargeId=a.chargeId) itemnamenum, 
    (select sum(TotalPrice) from vw_HC_getChargeItem where systype=2 and chargeId=a.chargeId) totalprice ,
    systype,chargeId,payer,UnitPrice,TotalPrice ,invoiceno 
    from vw_HC_getChargeItem a  where systype=2 
      

  4.   

    select 
        chargedeptId ,itemname ,count(itemname)as itemnamenum, sum(TotalPrice) as totalprice ,systype,chargeId,payer,UnitPrice,TotalPrice ,invoiceno 
    from 
        vw_HC_getChargeItem  
    where 
        systype=2 
    Group by 
        chargeId,chargedeptId ,itemname ,totalprice ,systype,chargeId,payer,UnitPrice,TotalPrice ,invoiceno
      

  5.   

    --或者是这个意思。
    select chargedeptId ,itemname ,count(itemname)as itemnamenum, sum(TotalPrice) as totalprice ,systype,chargeId,payer,
    UnitPrice,TotalPrice ,invoiceno 
    from vw_HC_getChargeItem  
    where systype=2 Group by chargedeptId ,itemname ,systype,chargeId,payer,UnitPrice,TotalPrice ,invoiceno