表结构是这样的
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改怎么写啊?
------解决方案--------------------
select lot_no,customer,sum(total ) ,no from table group by lot_no,no,customer
------解决方案--------------------
什么数据库?
for example
- SQL code
select distinct substr(lot_no, 1, instr(lot_no, '#')-1) as lot_no, customer, total, no from table
------解决方案--------------------
8好意思,错了,LZ不是选出不同,而是求和
- SQL code
select substr(lot_no, 1, instr(lot_no, '#')-1) as lot_no, customer, sum(total) ,no from table group by lot_no,no,customer
------解决方案--------------------
select substr(lot_no,1,4) as lot_no ,customer ,sum(total) ,no from 表 group by substr(lot_no,1,4),customer ,no
------解决方案--------------------
这是MySQL的
- SQL code
SELECT MID(lot_no,1,4), customer , SUM(total),no
FROM 表 GROUP BY MID(lot_no,1,4)
------解决方案--------------------
- Java code
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