求一个SQL语句?

yzflying 2003-09-24 03:13:48
表Product中有一个字段:产品类别(ProductType),共5种类别的产品,但每种类别的产品有几百种,我现在想选出每种类别的最新的一条纪录。

ID ProductType Name
1 a 11
2 a 22
3 a 55
4 b 66
5 b 22
6 c cc
7 c fasdf
8 a adf
9 d fasdf
......
我现在想得到,关于a、c、d、e、f的每个类别的最新的产品(ID递增)
...全文
34 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
9809375117 2003-09-24
  • 打赏
  • 举报
回复
select product.*
from product,
(select max(id) as id from product gourp by productType)b
where product.id=b.id
zjcxc 2003-09-24
  • 打赏
  • 举报
回复
select * from Product a where id=(select max(id) from Product where ProductType =a.ProductType )
aierong 2003-09-24
  • 打赏
  • 举报
回复




select *
from aii as a
where id=(select max(id) from aii as b where b.ProductType=a.ProductType)

select r.*
from aii as r join (select ProductType,max(id) as maxid from aii group by ProductType) as l
on r.id=l.maxid
aierong 2003-09-24
  • 打赏
  • 举报
回复
ID ProductType Name
1 a 11
2 a 22
3 a 55
4 b 66
5 b 22
6 c cc
7 c fasdf
8 a adf
9 d fasdf

select *
from tablename as a
where id=(select max(id) from tablename as b where b.ProductType=a.ProductType)
yujohny 2003-09-24
  • 打赏
  • 举报
回复
select * from 表 a where id=(select max(ID) from 表 where ProductType=a.ProductType)
aierong 2003-09-24
  • 打赏
  • 举报
回复


ID ProductType Name
1 a 11
2 a 22
3 a 55
4 b 66
5 b 22
6 c cc
7 c fasdf
8 a adf
9 d fasdf

select *
from tablename
where id in(select max(id) from tablename group by producttype)
txlicenhe 2003-09-24
  • 打赏
  • 举报
回复
Select a.* from 表 a
join
(Select ProductType,max(id) as id from 表 group by ProductType) b
on a.id = b.id

22,294

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧