如果是MYSQL,有点问题吧。
本帖最后由 alang85 于 2012-05-04 22:39 编辑
回复 1# yuhuohu
正确的写法如下:
SELECT MAX(a.sum_money), a.date_time
FROM (SELECT SUM(money) sum_money,
DATE(datetimes) date_time,
HOUR(datetimes) hour_time
FROM t1
GROUP BY DATE(datetimes), HOUR(datetimes)) a
GROUP BY a.date_time;
附带表结构:
CREATE TABLE `t1` (
`id` int(11) NOT NULL,
`employees_name` varchar(20) DEFAULT NULL,
`datetimes` datetime,
`money` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
测试数据语句如下:
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('1','甲','2012-04-10 10:10:10','1');
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('2','乙','2012-04-10 10:10:10','2');
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('3','丙','2012-04-10 10:10:10','3');
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('4','丁','2012-04-10 10:10:10','4');
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('5','甲','2012-04-10 11:10:10','2');
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('6','乙','2012-04-10 11:10:10','3');
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('7','丙','2012-04-10 11:10:10','3');
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('8','丁','2012-04-10 11:10:10','5');
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('9','甲','2012-04-11 10:10:10','3');
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('10','乙','2012-04-11 10:10:10','6');
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('11','丙','2012-04-11 10:10:10','5');
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('12','丁','2012-04-11 10:10:10','8');
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('13','甲','2012-04-11 11:10:10','2');
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('14','乙','2012-04-11 11:10:10','3');
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('15','丙','2012-04-11 11:10:10','3');
insert into `t1` (`id`, `employees_name`, `datetimes`, `money`) values('16','丁','2012-04-11 11:10:10','5');
发现自己看不懂了,退化严重
页:
1
[2]