表结构是这样的 id        lot_no     customer    total     no
  1       G632#0005     小A        300      T1   
  2       G132#0001     小B        200      T2
  3       G132#0002     小B        500      T2 
我要查询出来的结果是这样的lot_no  customer total   no
 G632     小A     300    T1
 G132     小B     700    T2
请问这条sql改怎么写啊?

解决方案 »

  1.   

    select lot_no,customer,sum(total ) ,no  from table group by lot_no,no,customer  
      

  2.   

    什么数据库?
    for example
    select distinct substr(lot_no, 1, instr(lot_no, '#')-1) as lot_no,
           customer, total, no
      from table
      

  3.   

    8好意思,错了,LZ不是选出不同,而是求和
    select substr(lot_no, 1, instr(lot_no, '#')-1) as lot_no, 
           customer, sum(total) ,no 
      from table 
      group by lot_no,no,customer  
      

  4.   

    select substr(lot_no,1,4) as lot_no ,customer ,sum(total) ,no from 表 group by substr(lot_no,1,4),customer ,no
      

  5.   

    这是MySQL的SELECT MID(lot_no,1,4), customer , SUM(total),no
     FROM 表  GROUP BY  MID(lot_no,1,4) 
      

  6.   


    select substr(lot_no, 1, instr(lot_no, '#')-1) as lot_no, 
           customer, sum(total) ,no 
      from table 
      group by substr(lot_no, 1, instr(lot_no, '#')-1) ,no ,customer 
      

  7.   


    --oracle
    select substr(a.lot_no,0,4) as lot_no,a.customer,b.total,a.no
    from table1 a,(
    select min(id),sum(total) as total
    from table1 
    group by customer
    ) b
    where a.id=b.id#mysql
    select SUBSTRING(lot_no,0,4),customer,sum(total) as total,no
    from table1 
    group by customer