codeigniter高级mysql求和查询

时间:2017-01-26 13:41:07

标签: mysql codeigniter-3

我有一个包含以下数据的mysql表,

Table name: test

purchaseno    spent totbdj
1             100   500
1             100   500
2             200   1000
2             300   1000

请帮助使用codeigniter mysql查询来实现以下输出

purchaseno   spent  totbdj
1            200    500
2            500    1000

1 个答案:

答案 0 :(得分:0)

只需使用SUM函数和GROUP BY子句:

SELECT purchaseno,
       SUM(spent) AS spent,
       totbdj
FROM test
GROUP BY purchaseno, totbdj