我有一个包含以下数据的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
答案 0 :(得分:0)
只需使用SUM
函数和GROUP BY
子句:
SELECT purchaseno,
SUM(spent) AS spent,
totbdj
FROM test
GROUP BY purchaseno, totbdj