我已经编写了自己的快速评论/编程文本,这远非正确,但会说明我想通过 sql 在数据库中做什么。
希望任何具有 SQL Server 编程技能的人 - 存储过程编程。可以帮助我,找出这是否可能。
我在 Oracle 的 PLSQL 方面有一点经验,所以我知道这可能是可能的。
我希望这个例子能自我解释,但如果没有,请让我对我在下面给出的 sql/c#/comment 示例进行深入解释。
storedProcedure(firstWeek, lastWeek)
{
Dictornary list = new OrderdDictornary(); //Key is a week, value is a list of tests
//Run through each week.
for(int i = firstWeek; i<=lastWeek; i++)
{
var queryList =
{
//All in the database
SELECT instrumentID
FROM Tests
GROUP BY InstrumentID
EXCEPT
//All that could be found in this week
SELECT InstrumentID
FROM Tests
WHERE TimeCompleted = // In 'i' week (this week)
GROUP BY InstrumentID
}
list.Add(i, queryList); //Key, Values
}
return list;
}
最后我会有一个周键列表,其中的值是按周排序的正确数据。
谢谢阅读!