SQL Server的期末存货价值等于下个月的期初存货

时间:2018-07-31 02:37:19

标签: sql-server

我的库存表包含三列:月,年和期末库存,如下所示:

Month   Year      CLosingstock
------------------------------
Jan     2017          10
Feb     2017          20
Mar     2017          30
Dec     2017          40
Jan     2018          50
Feb     2018          60

我想创建新的期初库存列,2017年1月的value(10)应该是2017年2月的期初库存。

1 个答案:

答案 0 :(得分:0)

使用窗口功能List<NpcDrop> fullNPCDropsList; DataTable gridTable; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { fullNPCDropsList = GetData1(); dgvListData.DataSource = fullNPCDropsList; gridTable = GetData2(); dgvDataTableData.DataSource = gridTable; } private List<NpcDrop> GetData1() { List<NpcDrop> drop = new List<NpcDrop>(); int start = 201000; for (int i = 0; i < 100; i++) { drop.Add(new NpcDrop(++start)); } return drop; } private DataTable GetData2() { DataTable dt = new DataTable(); dt.Columns.Add("ID", typeof(string)); int start = 201000; for (int i = 0; i < 100; i++) { dt.Rows.Add((++start).ToString()); } return dt; } private void txtListSearchBox_TextChanged(object sender, EventArgs e) { if (txtListSearchBox.Text == "") { dgvListData.DataSource = fullNPCDropsList; } else { if (int.TryParse(txtListSearchBox.Text, out int value)) { List<NpcDrop> filterList = fullNPCDropsList.FindAll(x => x.ID.Equals(value)); dgvListData.DataSource = filterList; } } } private void txtDTSearchBox_TextChanged(object sender, EventArgs e) { if (txtDTSearchBox.Text == "") { dgvDataTableData.DataSource = gridTable; } else { DataView filterData = new DataView(gridTable); filterData.RowFilter = "ID LIKE '%" + txtDTSearchBox.Text + "%'"; dgvDataTableData.DataSource = filterData; } } 。我假设您的LAG()是整数而不是字符串

Month