SQL(或Linq)选择以前的值 [英] SQL (or Linq) Select previous value

查看:70
本文介绍了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)选择以前的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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