SQL(或Linq)选择以前的值

编程入门 行业动态 更新时间:2024-10-21 16:33:58
本文介绍了SQL(或Linq)选择以前的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嘿所有, 我想根据DateTime值(特别是年份)从当前记录中的一个记录中选择一个值正在输入和已经在那里(除非第一行)。我的id因为删除而跳过(我认为修复它的方法也适用)。 有人想帮我查询吗? (注意:我之前已经重新订购了ID,但是我忘记了当我这样做时使用了哪种语言,我似乎无法找到它的参考,这样做通常看起来像是浪费资源) 。 谢谢, Ruben

Hey all, I would like to select a value from a record that is one previous from the current record based on the DateTime value (specifically: year) that is being input and one that is already in there (unless first row). My id's skip because of deletes (I suppose a fix-it method for that would work too). Anyone want to help me with the query? (Note: I have re-ordered ID's before, but I forget which language that was in when I did it, I can't seem to find a reference on that, and doing that often seems like it would be a waste of resources). Thanks, Ruben

推荐答案

我希望这可以帮到你 I hope this help you //list object var lstValue = new List<int>(); //insert 0 -> 19 for (var i = 0; i < 20; i++) lstValue.Add(i); //set up currentValue var crValue = 3; //sort list by lstValue = lstValue.OrderByDescending(s => s).ToList(); //get index of current value var index = lstValue.IndexOf(crValue); Console.WriteLine(index); //get value previous if (index > 0) { var prvValue = lstValue.Skip(index - 1).First(); Console.WriteLine(prvValue); }

更多推荐

SQL(或Linq)选择以前的值

本文发布于:2023-10-28 19:26:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537566.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SQL   Linq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!