摘要树问题SQL

时间:2013-01-09 10:43:13

标签: sql-server tree treeview hierarchy

  

这是我的代码的结果,但我将总结一下例如nodid 1.1和1.2   报告:发票附录

  1.   

    InvoiceNo 8027944
      ExtRef:1600056051
      订购金额3 395 300,00 kr
      Ordername注册i Fenix E
      休息:3 395 300,00 kr
      发票日期2012-11-06

  2. 这是我的输出,但这不对

     Our reference   Nod_id     In nodid   amount
    1960110000       1.1        1              0,00    
    1960110001       1.1.1      1.1        29000,00       
    1960120000       1.1.2      1.1         5000,00
    1960130000       1.2        1              0,00
    1960130001       1.2.1      1.2         1920,00
    
  3.   

    1. 我有这个输出

       Our reference   Nod_id     In nodid   amount
      1960110000       1.1        1          34000,00<br>
      1960130000       1.2        1           1920,00</li>
      
           

      我的问题是我将Summury为exampel Row whit Nod_id 1.1和1.2但我将有我们的参考1960110000和描述Pos 1 ......   我的代码

    sql, 1 DBSELECT 
    t.project,
    t.work_order as projakt,
    t1.orderram,
    t2.flag ,
    t2.ext_inv_ref,
    t2.work_order,
    t2.used_hrs,
    t2.cur_amount as belopp,
    t4.description, 
    t5.nod_id_2 as ing_nodid,
    t5.nod_id_1 as nodid,
    t5.ingar_pakt as namn,
    t2.work_order,
    SUM(t2.used_hrs) as used_hrs,
    SUM(t2.cur_amount) as belopp
    from  atsworkorder t
    left join  afx01projact4  t5 on t.client =t5.client and t.work_order = t5.dim_value and t5.attribute_id = 'BF' 
    left join afx01projact2  t1 on t.client=t1.client and t.work_order = t1.dim_value
    left join atsinvhistr t2 on t.client=t2.client and t.work_order  = t2.work_order and '<datum>' >= t2.voucher_date
    left join agldescription t4 on t.client =t4.client and t4.dim_value = t.work_order
    where  t.project ='<proj>'  and t.client = '<client>'  
    group by
    t.project,
    t.work_order,
    t2.work_order,
    t5.nod_id_1,
    t5.dim_value,
    t5.nod_id_2 ,
    t5.ingar_pakt ,
    t1.orderram,
    t2.flag,
    t2.ext_inv_ref,
    t2.used_hrs,
    t2.cur_amount,
    t4.description
    order by nodid
    

0 个答案:

没有答案