如何选择日期时间值的最大值 [英] how to select Maximum value of datetime value

查看:229
本文介绍了如何选择日期时间值的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表是:



My table is:

ProcessMode ProcessDate ProcessTime CardNo  EffectiveDate   EffectiveTime   ExpireDate  ExpireTime  HolderName  EffectiveDate1
1   12/21/2011  10:04:14    0749    12/21/2011  00:00           Martin Francis 1366
1   12/21/2011  10:06:04    0749    12/21/2011  00:00           Martin Francis 1366
1   07/09/2013  13:00:14    0749    07/09/2013  00:00           Martin Francis 1366
1   07/09/2013  14:33:24    0749    07/09/2013  00:00           Martin Francis 1366
1   07/10/2013  12:42:58    0749    07/10/2013  12:30           Martin francis 1366
2   12/21/2011  10:30:20    0749            12/21/2011  10:30   Martin Francis 1366
2   07/09/2013  14:33:26    0749            07/09/2013  14:30   Martin Francis 1366
2   07/10/2013  12:30:03    0749            07/10/2013  12:30   Martin francis 1366
2   07/10/2013  13:23:15    0749            07/10/2013  13:00   Martin francis 1366
2   07/10/2013  14:28:59    0749            07/10/2013  14:00   Martin francis 1366
2   07/10/2013  14:59:23    0749            07/10/2013  14:30   Martin Francis 1366


I need to select the maximum value of EffectiveDate (MM/dd/yyyy).but that EffectiveDate  is taken in string value

 i Want Result would be:

ProcessMode	ProcessDate	ProcessTime	CardNo	EffectiveDate	EffectiveTime	ExpireDate	ExpireTime	HolderName	EffectiveDate1
1	07/10/2013	12:42:58	0749	07/10/2013	12:30			Martin francis 1366











但是我尝试了一个代码。

var AutoEffectExpireData =SELECT * FROM(SELECT AutoEffectExpireData.CardNo,Max(AutoEffectExpireData.EffectiveDate)AS EffectiveDate FROM AutoEffectExpireData GROUP BY AutoEffectExpireData.CardNo)AS CardNo INNER JOIN AutoEffectExpireData t1 ON CardNo.CardNo = t1.CardNo和CardNo.EffectiveDate = t1 .EffectiveDate ;





但输出是这样的。



ProcessMode ProcessDate ProcessTime CardNo EffectiveDate EffectiveTime ExpireDate ExpireTime HolderName EffectiveDate1

1 12/21/2011 10:04:14 0749 12/21/2011 00:00 Martin Francis 1366






but i tried one code.
var AutoEffectExpireData = " SELECT * FROM (SELECT AutoEffectExpireData.CardNo,Max(AutoEffectExpireData.EffectiveDate) AS EffectiveDate FROM AutoEffectExpireData GROUP BY AutoEffectExpireData.CardNo ) AS CardNo INNER JOIN AutoEffectExpireData t1 ON CardNo.CardNo = t1.CardNo and CardNo.EffectiveDate = t1.EffectiveDate ";


but output is came like this.

ProcessMode ProcessDate ProcessTime CardNo EffectiveDate EffectiveTime ExpireDate ExpireTime HolderName EffectiveDate1
1 12/21/2011 10:04:14 0749 12/21/2011 00:00 Martin Francis 1366

推荐答案

据我所知,如果你只需要最大生效日期,请尝试这个,
As i understand ur question if u only needs the max effective date then try this,
SELECT * FROM AutoEffectExpireData AEED  where datetime = (SELECT MAX(AEED.EffectiveDate) FROM topten AutoEffectExpireData
       GROUP BY clos..)Group by AEED.EffectiveDate ORDER BY AEED.EffectiveDate desc


hi ehsan,

请回复,但我需要知道您发送的查询中的Group By Clos ...
hi ehsan,
Thnks for the reply but i need to know what is Group By Clos... in the query which you have sent.


这篇关于如何选择日期时间值的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆