日期:2014-05-17  浏览次数:20920 次

oracle简单语句求助
例如 
A表
user_id name time
33 www 2010-05-06
33 www 2010-06-07
33 www 2010-07-08
44 www 2010-05-07
44 www 2010-06-07

查询后
B表
user_id name time
33 www 2010-07-08
44 www 2010-06-07


这SQL怎么写???
即根据user_id把time最大的选出来组成一张表,我第一次接触oracle ,不太会,还请各位高手帮帮忙啊~~~

------解决方案--------------------
SQL code

select user_id,name,max(time)
from a
group by user_id,name

------解决方案--------------------
SQL code

create table a
(user_id number(8),
name varchar2(20),
time date);

insert into a values(33,'www',to_date('2010-07-08','yyyy-mm-dd'));
insert into a values(33,'www',to_date('2010-06-07','yyyy-mm-dd'));
insert into a values(33,'www',to_date('2010-05-06','yyyy-mm-dd'));
insert into a values(44,'www',to_date('2010-05-07','yyyy-mm-dd'));
insert into a values(44,'www',to_date('2010-06-25','yyyy-mm-dd'));


create table b
(user_id number(8),
name varchar2(20),
time date);

insert into b (
select  user_id,name,max(time)
from a
group by user_id,name);

------解决方案--------------------
探讨
很详细
SQL code

create table a
(user_id number(8),
name varchar2(20),
time date);

insert into a values(33,'www',to_date('2010-07-08','yyyy-mm-dd'));
insert into a values(33,'www',to_date('2010-06-07','yy……

------解决方案--------------------
select user_id name ,max(time) from A group by user_id
------解决方案--------------------
select user_id ,name,max(time) from a group by user_id;