表A,字段:id,name,total,三字段
           1   xiao  5
           2   da    2
           2   xiao  3
           2   xiao  1
           3   wang  3
           ……
求:select id,sum(total) from 表A
    select id,sum(total) from 表A where name='xiao'
我想把这两条sql语句合并成一条,如何实现?(注:是mysql中)

解决方案 »

  1.   

    select   id,sum(total)   from   表A union all       select   id,sum(total)   from   表A   where   name= 'xiao ' 
      

  2.   

    select   id,sum(total)   from   表A union all 
            select   id,sum(total)   from   表A   where   name= 'xiao ' 
      

  3.   

    select   id,sum(total)   from   表A union all
    select   id,sum(total)   from   表A   where   name= 'xiao '
      

  4.   

    select id,sum(total)   from   表A union all select   id,sum(total)   from   表A   where   name= 'xiao '