thinkphp按日期(天)统计数据

··

            $data = $orderModel->alias('m')->field('FROM_UNIXTIME(m.enddate,"%Y-%m-%d") as enddate,count(m.id) as sn_sum,sum(m.real_price) as rmb_sum,sum(m.use_up) as use_up_sum,o.sn as machine_sn')
			->join('__MACHINE__ o ON m.machine_id=o.id', 'LEFT')
			->where($where)
			->group('m.machine_id,FROM_UNIXTIME(m.enddate,"%Y-%m-%d")')
			->order('m.enddate DESC')
			->limit($start . ',' . $limit)
			->select();
		$subQuery = $orderModel->alias('m')->field('FROM_UNIXTIME(m.enddate,"%Y-%m-%d") as enddate,count(m.id) as sn_sum,sum(m.real_price) as rmb_sum,sum(m.use_up) as use_up_sum,o.sn as machine_sn')
			->join('__MACHINE__ o ON m.machine_id=o.id', 'LEFT')
			->where($where)
			->group('m.machine_id,FROM_UNIXTIME(m.enddate,"%Y-%m-%d")')
			->order('m.enddate DESC')
			->buildSql();
		$count = $orderModel->table($subQuery . ' a')->count();

··

你可能感兴趣的:(mysql)