# 表的结构 `wsz1`
#CREATE TABLE `wsz1` (
`id` int(11) NOT NULL,
`name` varchar(10) NOT NULL,
`money` varchar(20) NOT NULL,
`time` datetime NOT NULL,
UNIQUE KEY `id` (`id`),
KEY `time` (`time`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;#
# 导出表中的数据 `wsz1`
#INSERT INTO `wsz1` (`id`, `name`, `money`, `time`) VALUES (1, 'a', '10', '2010-10-01 00:00:00'),
(2, 'b', '20', '2010-10-01 00:00:00'),
(3, 'a', '11', '2010-11-01 00:00:00'),
(4, 'b', '12', '2010-11-01 00:00:00'),
(6, 'c', '11', '2010-12-01 00:00:00');
-------------------------------
实现成下结果:
name money time
c 11 2010-12-01
b 12 2010-11-01
a 11 2010-11-01
#CREATE TABLE `wsz1` (
`id` int(11) NOT NULL,
`name` varchar(10) NOT NULL,
`money` varchar(20) NOT NULL,
`time` datetime NOT NULL,
UNIQUE KEY `id` (`id`),
KEY `time` (`time`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;#
# 导出表中的数据 `wsz1`
#INSERT INTO `wsz1` (`id`, `name`, `money`, `time`) VALUES (1, 'a', '10', '2010-10-01 00:00:00'),
(2, 'b', '20', '2010-10-01 00:00:00'),
(3, 'a', '11', '2010-11-01 00:00:00'),
(4, 'b', '12', '2010-11-01 00:00:00'),
(6, 'c', '11', '2010-12-01 00:00:00');
-------------------------------
实现成下结果:
name money time
c 11 2010-12-01
b 12 2010-11-01
a 11 2010-11-01
+------+-------+---------------------+
| name | money | time |
+------+-------+---------------------+
| c | 11 | 2010-12-01 00:00:00 |
| b | 12 | 2010-11-01 00:00:00 |
| a | 11 | 2010-11-01 00:00:00 |
+------+-------+---------------------+
+------+-------+------------+
| name | money | time |
+------+-------+------------+
| c | 11 | 2010-12-01 |
| b | 12 | 2010-11-01 |
| a | 11 | 2010-11-01 |
+------+-------+------------+
3 rows in set (0.00 sec)
[征集]分组取最大N条记录方法征集,及散分....
-> from wsz1 a
-> where not exists (select 1 from wsz1 where name=a.name and time>a.time)
-> order by name desc;
+------+-------+------------+
| name | money | date(time) |
+------+-------+------------+
| c | 11 | 2010-12-01 |
| b | 12 | 2010-11-01 |
| a | 11 | 2010-11-01 |
+------+-------+------------+
3 rows in set (0.03 sec)mysql>
实现成下结果:
name money time add tel group
c 11 2010-12-01 bj 65432188 组一
b 12 2010-11-01 bj 88888888 组二
a 11 2010-11-01 sh 85585856 组一实在不成我可以加分
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。