有一表中数据如下:
2003-01-02 k001 m002 200.00
2003-01-02 k001 m002 300.00
2003-01-03 k001 m002 200.00
2003-01-03 k001 m002 300.00
2003-01-03 k001 m003 200.00
2003-01-04 q001 m004 200.00
2003-01-04 q001 m005 300.00
.... ... ... ...
得到如下数据:
2003-01-02 k001 m002 500.00
2003-01-03 k001 m002 500.00
2003-01-03 k001 m003 200.00
2003-01-04 q001 m004 200.00
2003-01-04 q001 m005 300.00
... ... ... ...
select field1,field2,field3,sum(field4) from table order by 1 group by field1,file2,file3
先求和,用sum;再用order 排序;最后用group排序;
group by Field1:就是Field1相同的合并
group by Field1,Field2 就是Field1,Field2都相同的合并
group by Field1,Field2,Field3 就是Field1,Field2,Field3都相同的合并
2003-01-02 k001 m002 200.00
2003-01-02 k001 m002 300.00
2003-01-03 k001 m002 200.00
2003-01-03 k001 m002 300.00
2003-01-03 k001 m003 200.00
2003-01-04 q001 m004 200.00
2003-01-04 q001 m005 300.00
.... ... ... ...
得到如下数据:
2003-01-02 k001 m002 500.00
2003-01-03 k001 m002 500.00
2003-01-03 k001 m003 200.00
2003-01-04 q001 m004 200.00
2003-01-04 q001 m005 300.00
... ... ... ...
select field1,field2,field3,sum(field4) from table order by 1 group by field1,file2,file3
先求和,用sum;再用order 排序;最后用group排序;
group by Field1:就是Field1相同的合并
group by Field1,Field2 就是Field1,Field2都相同的合并
group by Field1,Field2,Field3 就是Field1,Field2,Field3都相同的合并