SQL语句问题(20分)

  • 主题发起人 主题发起人 zhouwenlin_1
  • 开始时间 开始时间
Z

zhouwenlin_1

Unregistered / Unconfirmed
GUEST, unregistred user!
表aa中有2个列,Caigoudanid和nowdate 分别代表采购单号和当前日期<br><br>YKCG08072301~~~YKCG08072318<br><br>select max(right(rtrim(Caigoudanid),2)) as i2 from aa &nbsp;//得到尾数最大的采购单<br><br>i2:=ADOQuery1.FieldByName('i2').AsInteger;<br><br>i2=18<br><br>但我还想得到尾数最大的采购单的尾数和它对应的日期<br><br>应该怎样写SQL语句啊???<br><br>先谢谢了啊
 
可以直接<br>select max(right(rtrim(Caigoudanid),2)) as i2,nowdate from aa<br>group by right(rtrim(Caigoudanid),2))<br>order by max(right(rtrim(Caigoudanid),2)) desc<br>limit 1<br><br>group by right(rtrim(Caigoudanid),2))如果不支持则直接改为<br>group by Caigoudanid
 
Oracle语法:<br><br>select max(substr(Caigoudanid,length(Caigoudanid),1)),nowdate from aa<br>group by nowdate
 
select top 1 Caigoudanid ,nowdate <br>from aa &nbsp;<br>order by Caigoudanid desc
 
用这个试试吧:<br>Select Caigoudanid, nowdate From aa <br>Where Caigoudanid = (Select MAX(RIGHT(RTRIM(Caigoudanid),2)) From aa)
 
后退
顶部