本帖最后由 benaheng 于 2013-04-09 17:30:26 编辑

解决方案 »

  1.   

    第一个问题,因为你group by了4个字段,而这4个字段何在一起,就是单独的一行,所以其实是sum了,但是都是每行sum,这里可能需要改成子查询先sum然后带出其他字段
      

  2.   

    问题2,估计你用了inner join 或者直接table1,table2,table3这样的格式,改成外联结,但是怎么连恐怕要你自己才知道,你的表有点套模糊了
      

  3.   

    第一个问题没看懂第二个问题如果表2表3有重复,需要去除重复再join.
      

  4.   

    不知道你要查什么,你看看是不是你想要的SELECT  Accounts ,
            erjidaili ,
            o.ticheng2 ,
            Expr1 ,
            fandian2
    FROM    ( SELECT    a.Accounts ,
                        a.erjidaili ,
            --o.ticheng2 ,
                        o.Accounts AS Expr1 ,
                        SUM(o.ticheng2) AS fandian2
              FROM      QPTreasureDB.dbo.OnLineOrder o ,
                        QPAccountsDB.dbo.AccountsInfo a
              WHERE     o.OrderStatus = '2'
                        AND o.Accounts = a.Accounts
                        AND a.erjidaili = 'test100'
              GROUP BY  a.Accounts ,
                        a.erjidaili ,
            --o.ticheng2 ,
                        o.Accounts
            ) a
            INNER JOIN QPTreasureDB.dbo.OnLineOrder o ON o.Accounts = a.Accounts
      

  5.   

    select a.Accounts, a.erjidaili,o.Accounts AS Expr1, SUM(o.ticheng2) AS fandian2 
    from QPTreasureDB.dbo.OnLineOrder o,QPAccountsDB.dbo.AccountsInfo a 
    where o.OrderStatus='2' and o.Accounts=a.Accounts and a.erjidaili='test100' 
    GROUP BY a.Accounts, a.erjidaili, o.Accounts