group by OPTNO,CURRENCYCURRENCY 是币种的意思吧,group by OPTNO应该可以了~~~~

解决方案 »

  1.   

    如果把currency去掉的话,会报错“'FeeResult.Currency' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。”
      

  2.   

    楼主,好像应该不是这样设计的,比如汇率应该与币种在一起的~~~比如:
    OptNO    currency    汇率     PreMoney 这样就简单多了,而且这样也更符合设计要求,不然汇率一更改的话以前的汇率和现在的汇率又不好区分了~~~
      

  3.   

    楼上的DX,我没弄清楚您的意思,汇率我们专门有一个表,目前我是用8代替的
    您看看我这个语句为什么如果currency只有RMB或只有USD,是显示一行结果的,但如果既有RMB又有USD,还是显示两行呢?
      

  4.   

    如果既有RMB又有USD,那么应该显示成什么哪??
    你的方法对于只有一个是好用的,那么就把源数据进行一下处理,然后再用你的方法。
      

  5.   

    select * from 
    (
    select 
    OptNO as 编号,
    isnull (case currency
                     when 'RMB'then
                    rtrim(sum(case inout
                     when 'in' then  PreMoney else 0 end))end,'0.00') as 人民币收入,
    isnull (case currency
                     when 'RMB'then
                    rtrim(sum(case inout
                     when 'Out' then  PreMoney else 0 end))end,'0.00') as 人民币支出,
    isnull (case currency
                     when 'USD'then
                    rtrim(sum(case inout
                     when 'in' then  PreMoney*8 else 0 end))end,'0.00') as 美金收入,
    isnull (case currency
                     when 'USD'then
                    rtrim(sum(case inout
                     when 'Out' then  PreMoney*8 else 0 end))end,'0.00') as 美金支出
     from FeeResult where OptNO ='SPCJXEE06071111' and feetype='单票'
    group by OPTNO,CURRENCY
    )T group by CURRENCY