按今天,月和年汇总数据

时间:2018-03-27 06:03:01

标签: php sql codeigniter sum

我想按今天,月份和年份汇总数据。已经使用分组但没有工作

我的控制器代码:

$total_steamer = $this->dynamic_model->read('sys_material', 0, 0, 'material_status != 5', false, false, 'SUM(A.material_piece_qty_printed) val ')->row();

$ts =  $total_steamer->val;

$this->view['data'] += 'ts' => $ts;

任何想法?

我想要输出

steam today: 10

steam this month: 20

steam this year: 50

1 个答案:

答案 0 :(得分:0)

尝试使用此查询获取“月,年”num_calls

的总和
SELECT MONTH(`date`) AS m, YEAR(`date`) AS y, COUNT(`id`) as count FROM table GROUP BY m, y