怎样从三个表中查询想要的数据,有数量和金额要求汇总,并且要求排序。最后生成一个表,将其插入?

解决方案 »

  1.   

    insert into #ttselect * from table
      

  2.   

    --例子select a.id , count(a.数量) 数量 ,sum(a.金额) 金额 into newtablename 
    from table1 a , table2 b
    where a.id = b.id
    group by id
      

  3.   

    看错了,是要生成表,select ***
    into #tb
    from table 
    where ...
      

  4.   

    select sum(总数量) as '',sum(金额) as '总金额'
    into test--生成表名
    from (select sum(数量) as '数量',sum(金额) as '金额' from table1
    union all 
    select sum(数量),sum(金额) from table2
    union all 
    select sum(数量),sum(金额) from table3)taselect [总数量]=sum(table1.数量)+sum(table2.数量)+sum(table3.数量),
    [总金额]=sum(table1.金额)+sum(table2.金额)+sum(table3.金额)
    into test--生成表名
    from table1,table2,table3