一个SQL语句,急!

bpaibgy 2003-05-08 12:59:32
在一表中,有字段prod,date,同一个prod值,对应有很多个data,写一个selsct语句,把不同的prod中对应的最大的data值的记录取出来,该怎么写,请指教!
...全文
6 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
benxie 2003-05-09
create table a (a varchar(10),b int)

insert into a values ('a',1)
insert into a values ('a',2)
insert into a values ('a',3)
insert into a values ('b',1)
insert into a values ('b',2)
insert into a values ('b',3)

select a,max(b) from a group by a
a b
---------- -----------
a 3
b 3

(所影响的行数为 2 行)
回复
Michael2003 2003-05-08
select *, a.[data] as maxdata from table as a where a.[data]=(select max(b.[data]) from table as b where a.[prod]=b.[proc] group by b.[prod]
回复
shengjun791031 2003-05-08
select prod,max(data) as maxdata from table1 group by prod
回复
kinny_ke 2003-05-08
up
回复
fyg_02971 2003-05-08
select prod,max(date) as maxDate from table group by prod
回复
xiajianfeng 2003-05-08
select (select max([date]) from table where prod=a.prod) as number ,* from table as a
回复
cappuccinomn 2003-05-08
select prod,max(date) as MaxDate from table group by prod
回复
飞天林 2003-05-08
select prod,max(date) as MaxDate from table group by prod
回复
cbzdream 2003-05-08
select prod,max([date]) as Max_Date from table group by prod
回复
ttyp 2003-05-08
SELECT * FROM TABLENAME A WHERE DATE = (SELECT MAX(DATE) FROM TABLENAME B WHERE A.PROD = B.PROD)
回复
blactte 2003-05-08
select prod,max([date]) as Max_Date from table group by prod
回复
dapper 2003-05-08
SELECT PROD,MAX(DATE) AS newDATE FROM TABELNAME GROUP BY PROD
回复
CrazyFor 2003-05-08
select prod,max([date]) as Max_Date from table group by prod
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2003-05-08 12:59
社区公告
暂无公告