查询未从数据库中检索最大日期 [英] Query not Retrive Maximum date from the Database

查看:83
本文介绍了查询未从数据库中检索最大日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有人的Helloo,

我有一个没有给出最大日期的查询,表示最新日期.
如果我有一些记录,如:formare dd/MM/yyyy

14/07/2012,
2012年1月21日,
2012年10月1日,
2012年8月14日.

所以我想检索日期:14/8/2012,因为它是整体上的最新日期.我使用查询但不起作用:

Helloo To All,

i have a query which does not give Maximum date means latest date.
if i have some Records like: formare like dd/MM/yyyy

14/07/2012,
21/01/2012,
10/01/2012,
14/08/2012.

so i want to retrive the date :14/8/2012 because it is latest date from the whole. i use the query but not work :

SELECT title,descr FROM latest_news WHERE (date=(SELECT  MAX(date) FROM  latest_news ))


所以请抱我....

问候....
Mitesh


so please hlp me....

Regards....
Mitesh

推荐答案

从问题的角度看,我不认为您会喜欢这个答案...

我看到查询不起作用的唯一原因是您是否将日期存储为字符串.在这种情况下,日期"将使用字符串规则而不是日期/时间进行排序.最好的解决方案是更改数据库并将日期存储为DateTime值,而不是字符串.切勿将数字值(包括日期)存储为字符串-就像您所看到的那样,这样做非常非常困难,无法对它们进行任何形式的明智的数学运算或比较.
Form the look of your question, I don''t think you are going to like the answer...

The only reason I can see that the query will not work is if you have stored the date as a string. In which case, the "date" will be sorted using string rules, not date/time. The best solution is to change your database and store dates as DateTime value, not strings. Never store numeric values (including dates) as strings - it makes it very, very hard to do any form of sensible math or comparison on them - as you have seen.


这篇关于查询未从数据库中检索最大日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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