我想获取与最大序列号相对应的记录 [英] I want to get records corresponding to maximum serial number

查看:65
本文介绍了我想获取与最大序列号相对应的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我想获取与最大序列号相对应的记录

slno日期名称

1-22-12-2011-1 1/1/2012 Amrutha
1-22-12-2011-2 1/1/2012 Arjun
1-22-12-2011-3 2012年1月1日,阿尼莎(Anisha)

我想要一个查询,该查询返回对应于slno 1-22-12-2011-3的数据,我的意思是上一个postion.max的最大值.如何为它编写查询.我的数据库是MySQL.

在此先感谢
Amrutha

Hi all

I want to get records corresponding to maximum serial number

slno date name

1-22-12-2011-1 1/1/2012 Amrutha
1-22-12-2011-2 1/1/2012 Arjun
1-22-12-2011-3 1/1/2012 Anisha

I want a query which returns data corresponding to slno 1-22-12-2011-3 i mean maximum in last postion.how write query for it .my database is MySQL.

Thanks In Advance
Amrutha

推荐答案

最简单的方法是不将其作为单个对象存储在数据库中.从这里看起来它由5个组件组成:
The easiest way is to not store that in your DB as a single object. It looks from here to be made up of 5 components:
1-
22-12-2011-
1 
1/1/2012 
Text

如果要按任何这些顺序(或更可能是按某种组合)对结果进行排序,那么我会将它们存储为单独的数字值和基于DateTime的值,并在需要时重新组合序列号介绍.然后使用Sql ORDER BY子句很简单:

If you want to order results by any of these (or more probably by some combination of these) then I would store them as separate numeric and DateTime based values, and re-assemble the serial number when I needed it for presentation. Then it is a simple matter to use the Sql ORDER BY clause:

...ORDER BY manufactureDate, itemNumber ASC


将其作为一个文本字段在排序时会遇到很大的问题,因为当月初或当月初时,您必须应对2011年12月22日这一部分可能发生的长度变化.


Having it as one text field gives huge problems in sorting as you have to cope with the potential varying length on the 22-12-2011 part when it is early in the month, or the month is early in the year.


此查询可能会对您有所帮助.

This query may help you .

SELECT *  
FROM Table   
ORDER BY slno * 1 desc 
limit 1;


这篇关于我想获取与最大序列号相对应的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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