select MAX(日期) as "max_rq" from table
取字段值时:
fieldbyname("max_rq")即可取出最大日期
1.Select '表名' AS A,Max(时间) AS B From 表名
2.Selct A,B From (
Select '表名1' AS A,Max(时间) AS B From 表名1
Union All
Select '表名'2 AS A,Max(时间) AS B From 表名2
Union All
.......这部分你可以在DELPHI中写好
Union All
Select '表名n' AS A,Max(时间) AS B From 表名n ) C
WHERE B=(Selete Max(B) From C)
疑问:理论上同一表中,时间的最大值是唯一的,但对于多表,时间就有可能相等,也就是结果集中的记录数量存在大于一的可能性。
var NowDate,Date1,Date2,Date3,Date:TdateTime;大致如此。
MyList:TListString;
S:string;
begin
MyList:=TListString.Creat;;
NowDate:=Now;
Date1:=ClientDateSet1.FieldByName('时间').AsDateTime;
Date2:=ClientDateSet2.FieldByName('时间').AsDateTime;
Date3:=ClientDateSet3.FieldByName('时间').AsDateTime;
//......
if (NowDate-Date1)1<>
then Date:=Date1
esle Date:=Date2;
if Date>(NowDate-Date3) then Date:=Date3;
S:=DateTimetoString(ID,'yyyy-mm-dd hh:nn:ss',Date);
MyList.add('最近时间:'+S);
// ......
Memo1.Item.text:=MyList.Text;
Mylist.Free;
end;