select aa.a as AA,count(aa.b) as AAA from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A ,OrderLog.value('(//root/log[station="E"]/station)[1]','varchar(max)')as b  FROM tblOrderLogs where OrderLog.value('(root/log/addtime)[2]','datetime') between '2011-11-18 00:00:00' and '2011-11-18 23:59:59' and OrderLog.value('(//root/log[station="E"]/station)[1]','varchar(max)') is not null and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.Aselect aa.A as BB,count(aa.B) as BBB from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A ,OrderLog.value('(//root/log[station="K"]/station)[1]','varchar(max)')as b  FROM tblOrderLogs where OrderLog.value('(root/log/addtime)[2]','datetime') between '2011-11-18 00:00:00' and '2011-11-18 23:59:59' and OrderLog.value('(//root/log[station="K"]/station)[1]','varchar(max)') is not null and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.Aselect aa.A as CC,count(aa.B) as CCC from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A ,OrderLog.value('(//root/log[station="O"]/station)[1]','varchar(max)')as b  FROM tblOrderLogs where OrderLog.value('(root/log/addtime)[2]','datetime') between '2011-11-18 00:00:00' and '2011-11-18 23:59:59' and OrderLog.value('(//root/log[station="O"]/station)[1]','varchar(max)') is not null and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.A select aa.a as DD,DDD=sum(diff)/count(aa.b) from(select diff=DATEDIFF(minute ,paytime,outtime),OrderLog.value('(root/log[role="P"][station="A"]/account)[1]','varchar(20)')as a ,OrderLog.value('(//root/log[station="E"]/station)[1]','varchar(max)')as b from tblOrderLogs,tblorderbook,orderext  where tblOrderLogs.OrderID in(select  OrderID FROM dbo.tblOrderBook where orderstate='e') and outtime between '2011-10-08 00:00:00' and '2011-10-08 23:59:59' and orderext.orderno=tblorderbook.orderid and tblOrderLogs.orderid=tblorderbook.orderid)as aa group by aa.aselect aa.a as EE ,EEE=sum(aa.b) from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A,(FlightCost*AgentRate/100*AgioRate/100+TaxCost+TradingFee)as b from tblOrderLogs,tblorderbook,orderext  where tblOrderLogs.OrderID in(SELECT  OrderID FROM dbo.tblOrderBook where orderstate='e') and outtime between '2011-11-17 00:00:00' and '2011-11-17 23:59:59' and orderext.orderno=tblorderbook.orderid and tblOrderLogs.orderid=tblorderbook.orderid and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.a

解决方案 »

  1.   

    我合并时出现语法错误,求各位SQL高手救救我这个SQL菜鸟
    select  Y.TP as '工号', ISNULL(Y.PP,0)as '出票订单数量',ISNULL(Y.BBB,0)as '暂不能出票量',ISNULL(Y.CCC,0)as '取消订单量',ISNULL(R.DDD,0)as'平均出票时间' FROM
          ( select T.P as TP,T.PP,T.BBB,E.CCC from
     (select Q.AA as P,Q.AAA as PP,ISNULL(W.BBB,0) as BBB from
    (select aa.a as AA,count(aa.b) as AAA from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A ,OrderLog.value('(//root/log[station="E"]/station)[1]','varchar(max)')as b  FROM tblOrderLogs where OrderLog.value('(root/log/addtime)[2]','datetime') between '2011-11-18 00:00:00' and '2011-11-18 23:59:59' and OrderLog.value('(//root/log[station="E"]/station)[1]','varchar(max)') is not null and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.A) as Q left join
    (select aa.A as BB,count(aa.B) as BBB from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A ,OrderLog.value('(//root/log[station="K"]/station)[1]','varchar(max)')as b  FROM tblOrderLogs where OrderLog.value('(root/log/addtime)[2]','datetime') between '2011-11-18 00:00:00' and '2011-11-18 23:59:59' and OrderLog.value('(//root/log[station="K"]/station)[1]','varchar(max)') is not null and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.A )as W on Q.AA=W.BB ) as T left join 
                (select aa.A as CC,count(aa.B) as CCC from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A ,OrderLog.value('(//root/log[station="O"]/station)[1]','varchar(max)')as b  FROM tblOrderLogs where OrderLog.value('(root/log/addtime)[2]','datetime') between '2011-11-18 00:00:00' and '2011-11-18 23:59:59' and OrderLog.value('(//root/log[station="O"]/station)[1]','varchar(max)') is not null and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.A ) as E ON T.P=E.CC )as Y left join
        (select aa.a as DD,DDD=sum(diff)/count(aa.b) from(select diff=DATEDIFF(minute ,paytime,outtime),OrderLog.value('(root/log[role="P"][station="A"]/account)[1]','varchar(20)')as a ,OrderLog.value('(//root/log[station="E"]/station)[1]','varchar(max)')as b from tblOrderLogs,tblorderbook,orderext  where tblOrderLogs.OrderID in(select  OrderID FROM dbo.tblOrderBook where orderstate='e') and outtime between '2011-10-08 00:00:00' and '2011-10-08 23:59:59' and orderext.orderno=tblorderbook.orderid and tblOrderLogs.orderid=tblorderbook.orderid)as aa group by aa.a) as R  ON Y.TP=R.DD 
     
      

  2.   

    最好貼一下你的xml數據給大家看看
      

  3.   

    select aa.a as AA,count(aa.b) as AAA from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A ,OrderLog.value('(//root/log[station="E"]/station)[1]','varchar(max)')as b  FROM tblOrderLogs where OrderLog.value('(root/log/addtime)[2]','datetime') between '2011-11-18 00:00:00' and '2011-11-18 23:59:59' and OrderLog.value('(//root/log[station="E"]/station)[1]','varchar(max)') is not null and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.Aselect aa.A as BB,count(aa.B) as BBB from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A ,OrderLog.value('(//root/log[station="K"]/station)[1]','varchar(max)')as b  FROM tblOrderLogs where OrderLog.value('(root/log/addtime)[2]','datetime') between '2011-11-18 00:00:00' and '2011-11-18 23:59:59' and OrderLog.value('(//root/log[station="K"]/station)[1]','varchar(max)') is not null and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.Aselect aa.A as CC,count(aa.B) as CCC from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A ,OrderLog.value('(//root/log[station="O"]/station)[1]','varchar(max)')as b  FROM tblOrderLogs where OrderLog.value('(root/log/addtime)[2]','datetime') between '2011-11-18 00:00:00' and '2011-11-18 23:59:59' and OrderLog.value('(//root/log[station="O"]/station)[1]','varchar(max)') is not null and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.A select aa.a as DD,DDD=sum(diff)/count(aa.b) from(select diff=DATEDIFF(minute ,paytime,outtime),OrderLog.value('(root/log[role="P"][station="A"]/account)[1]','varchar(20)')as a ,OrderLog.value('(//root/log[station="E"]/station)[1]','varchar(max)')as b from tblOrderLogs,tblorderbook,orderext  where tblOrderLogs.OrderID in(select  OrderID FROM dbo.tblOrderBook where orderstate='e') and outtime between '2011-10-08 00:00:00' and '2011-10-08 23:59:59' and orderext.orderno=tblorderbook.orderid and tblOrderLogs.orderid=tblorderbook.orderid)as aa group by aa.aselect aa.a as EE ,EEE=sum(aa.b) from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A,(FlightCost*AgentRate/100*AgioRate/100+TaxCost+TradingFee)as b from tblOrderLogs,tblorderbook,orderext  where tblOrderLogs.OrderID in(SELECT  OrderID FROM dbo.tblOrderBook where orderstate='e') and outtime between '2011-11-17 00:00:00' and '2011-11-17 23:59:59' and orderext.orderno=tblorderbook.orderid and tblOrderLogs.orderid=tblorderbook.orderid and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.a
      

  4.   

    这是我合并的。。有错误
    select  u.tpp as '工号', ISNULL(U.PP,0)as '出票订单数量',ISNULL(U.BBB,0)as '暂不能出票量',ISNULL(U.CCC,0)as '取消订单量',ISNULL(.DDD,0)as'平均出票时间', ISNULL(X.EEE,0)as'出票金额' FROM
    (select  Y.TP as u.tpp, Y.PP,Y.BBB,Y.CCC,y.DDD FROM
      (select T.P as TP,T.PP,T.BBB,E.CCC from
         (select Q.AA as P,Q.AAA as PP,ISNULL(W.BBB,0) as BBB from
    (select aa.a as AA,count(aa.b) as AAA from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A ,OrderLog.value('(//root/log[station="E"]/station)[1]','varchar(max)')as b  FROM tblOrderLogs where OrderLog.value('(root/log/addtime)[2]','datetime') between '2011-11-17 00:00:00' and '2011-11-17 23:59:59' and OrderLog.value('(//root/log[station="E"]/station)[1]','varchar(max)') is not null and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.A)  as Q left join
        (select aa.A as BB,count(aa.B) as BBB from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A ,OrderLog.value('(//root/log[station="K"]/station)[1]','varchar(max)')as b  FROM tblOrderLogs where OrderLog.value('(root/log/addtime)[2]','datetime') between '2011-11-17 00:00:00' and '2011-11-17 23:59:59' and OrderLog.value('(//root/log[station="K"]/station)[1]','varchar(max)') is not null and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.A ) as W on Q.AA=W.BB )as T left join 
            (select aa.A as CC,count(aa.B) as CCC from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A ,OrderLog.value('(//root/log[station="O"]/station)[1]','varchar(max)')as b  FROM tblOrderLogs where OrderLog.value('(root/log/addtime)[2]','datetime') between '2011-11-17 00:00:00' and '2011-11-17 23:59:59' and OrderLog.value('(//root/log[station="O"]/station)[1]','varchar(max)') is not null and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.A ) as E ON T.P=E.CC )as Y left join
            (select aa.A as DD,DDD=sum(diff)/count(aa.b) from(select diff=DATEDIFF(minute ,paytime,outtime),OrderLog.value('(root/log[role="P"][station="A"]/account)[1]','varchar(20)')as a ,OrderLog.value('(//root/log[station="E"]/station)[1]','varchar(max)')as b from tblOrderLogs,tblorderbook,orderext  where tblOrderLogs.OrderID in(select  OrderID FROM dbo.tblOrderBook where orderstate='e') and outtime between '2011-11-17 00:00:00' and '2011-11-17 23:59:59' and orderext.orderno=tblorderbook.orderid and tblOrderLogs.orderid=tblorderbook.orderid)as aa group by aa.a) as R  ON Y.TP=R.DD)as U left join 
        (select aa.A as EE,EEE=sum(aa.b) from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A,(FlightCost*AgentRate/100*AgioRate/100+TaxCost+TradingFee)as b from tblOrderLogs,tblorderbook,orderext  where tblOrderLogs.OrderID in(SELECT  OrderID FROM dbo.tblOrderBook where orderstate='e') and outtime between '2011-11-17 00:00:00' and '2011-11-17 23:59:59' and orderext.orderno=tblorderbook.orderid and tblOrderLogs.orderid=tblorderbook.orderid and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.a)as x on U.TPP=X.EE消息 102,级别 15,状态 1,第 5 行
    '.' 附近有语法错误。
    消息 156,级别 15,状态 1,第 10 行
    关键字 'as' 附近有语法错误。
    消息 156,级别 15,状态 1,第 11 行
    关键字 'as' 附近有语法错误。
    消息 156,级别 15,状态 1,第 12 行
    关键字 'as' 附近有语法错误。
      

  5.   

    select  u.tpp as '工号', ISNULL(U.PP,0)as '出票订单数量',ISNULL(U.BBB,0)as '暂不能出票量',ISNULL(U.CCC,0)as '取消订单量',ISNULL(.DDD,0)as'平均出票时间', ISNULL(X.EEE,0)as'出票金额' FROM
    (select  Y.TP as [u.tpp], Y.PP,Y.BBB,Y.CCC,y.DDD FROM
      (select T.P as TP,T.PP,T.BBB,E.CCC from
         (select Q.AA as P,Q.AAA as PP,ISNULL(W.BBB,0) as BBB from
            (select aa.a as AA,count(aa.b) as AAA from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A ,OrderLog.value('(//root/log[station="E"]/station)[1]','varchar(max)')as b  FROM tblOrderLogs where OrderLog.value('(root/log/addtime)[2]','datetime') between '2011-11-17 00:00:00' and '2011-11-17 23:59:59' and OrderLog.value('(//root/log[station="E"]/station)[1]','varchar(max)') is not null and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.A)  as Q left join
            (select aa.A as BB,count(aa.B) as BBB from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A ,OrderLog.value('(//root/log[station="K"]/station)[1]','varchar(max)')as b  FROM tblOrderLogs where OrderLog.value('(root/log/addtime)[2]','datetime') between '2011-11-17 00:00:00' and '2011-11-17 23:59:59' and OrderLog.value('(//root/log[station="K"]/station)[1]','varchar(max)') is not null and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.A ) as W on Q.AA=W.BB )as T left join 
            (select aa.A as CC,count(aa.B) as CCC from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A ,OrderLog.value('(//root/log[station="O"]/station)[1]','varchar(max)')as b  FROM tblOrderLogs where OrderLog.value('(root/log/addtime)[2]','datetime') between '2011-11-17 00:00:00' and '2011-11-17 23:59:59' and OrderLog.value('(//root/log[station="O"]/station)[1]','varchar(max)') is not null and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.A ) as E ON T.P=E.CC )as Y left join
            (select aa.A as DD,DDD=sum(diff)/count(aa.b) from(select diff=DATEDIFF(minute ,paytime,outtime),OrderLog.value('(root/log[role="P"][station="A"]/account)[1]','varchar(20)')as a ,OrderLog.value('(//root/log[station="E"]/station)[1]','varchar(max)')as b from tblOrderLogs,tblorderbook,orderext  where tblOrderLogs.OrderID in(select  OrderID FROM dbo.tblOrderBook where orderstate='e') and outtime between '2011-11-17 00:00:00' and '2011-11-17 23:59:59' and orderext.orderno=tblorderbook.orderid and tblOrderLogs.orderid=tblorderbook.orderid)as aa group by aa.a) as R  ON Y.TP=R.DD)as U left join 
            (select aa.A as EE,EEE=sum(aa.b) from(select orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') as A,(FlightCost*AgentRate/100*AgioRate/100+TaxCost+TradingFee)as b from tblOrderLogs,tblorderbook,orderext  where tblOrderLogs.OrderID in(SELECT  OrderID FROM dbo.tblOrderBook where orderstate='e') and outtime between '2011-11-17 00:00:00' and '2011-11-17 23:59:59' and orderext.orderno=tblorderbook.orderid and tblOrderLogs.orderid=tblorderbook.orderid and orderlog.value('(//root/log[role="P"][station="A"]/account)[1]','varchar(20)') is not null)as aa group by aa.a)as x on U.TPP=X.EE
      

  6.   

    消息 207,级别 16,状态 1,第 2 行
    列名 'DDD' 无效。
    消息 207,级别 16,状态 1,第 9 行
    列名 'TPP' 无效。
    消息 207,级别 16,状态 1,第 1 行
    列名 'tpp' 无效。
    消息 4104,级别 16,状态 1,第 1 行
    无法绑定由多个部分组成的标识符 ".DDD"。求救、、、
      

  7.   

    感谢fredrickhu大神的提议,我后来自己改好了