sql 查询语句问题!

mugluo 2003-10-08 11:05:10
djh(单据号、字符型) ypdm(代码) mc(名称) dj(单价)
000362 215296 双黄莲胶囊 4.9
000565 215296 双黄莲胶囊 6
000607 215296 双黄莲胶囊 6

000502 21530 呋喃旦啶片 0.93
000568 21530 呋喃旦啶片 0.93
000841 21530 呋喃旦啶片 0.93
0001097 21530 呋喃旦啶片 0.93

请问高手,如何编写SQL语句才能使结果显示为:
000607 215296 双黄莲胶囊 6
0001097 21530 呋喃旦啶片 0.93
当代码相同,显示单据号最大的纪录。

thank you very much for your help.
...全文
113 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
gmlxf 2003-10-09
  • 打赏
  • 举报
回复
select * from 表 where djh in (select max(djh) from 表 group by ypdm)
Dennis618 2003-10-09
  • 打赏
  • 举报
回复

select a.djh,a.ypdm,mc from 表 a right join (select max(djh) as djh,ypdm from 表 group by ypdm) b on a.djh=b.djh and a.ypdm=b.ypdm
pengdali 2003-10-09
  • 打赏
  • 举报
回复
select * from 表 tem where djh=(select max(djh) from 表 where ypdm=tem.ypdm)
hbwhwanghua 2003-10-09
  • 打赏
  • 举报
回复
select max(djh),ypdm,mc from table group by ypdm,mc
playyuer 2003-10-09
  • 打赏
  • 举报
回复
典型的相关子查询
txlicenhe 2003-10-09
  • 打赏
  • 举报
回复
Select * from 表 a where djh = (select max(djh) from 表 where ypdm = a.ypdm)
maoyesky 2003-10-09
  • 打赏
  • 举报
回复
select * from yourtable where cast(djh as int) in ( max(cast(djh as int)) from yourtable group by ypdm)
hdslah 2003-10-09
  • 打赏
  • 举报
回复
select * from table a inner join (select ypdm,max(djh) djh from table group by ypdm) b on a.djh=b.djh)
meteorlg 2003-10-09
  • 打赏
  • 举报
回复
select * from table a where djh=(select max(djh) from table b where a.ypdm=b.ypdm)
CrazyFor 2003-10-09
  • 打赏
  • 举报
回复

select * from 表 as AA where not exists(select 1 from 表 as BB where aa.ypdm=bb.ypdm and cast(aa.djh as int) <cast(bb.djh as int))
yelook 2003-10-08
  • 打赏
  • 举报
回复
select a.* from table a inner join
(
select max(cast(djh as int)) as djh,ypdm from table group by ypdm
) b on cast(a.djh as int)=cast(b.djh as int) and a.ypdm=b.ypdm

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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