【发布时间】:2012-04-05 15:02:05
【问题描述】:
我有一个表格,其中存储了员工姓名和他们工作的年份。列是:
employeeID int NOT NULL,
year int NOT NULL
主键是复合的:employeeID 和 year。我需要选择该employeeID 存在2012 年而不是2011 年的表中的所有记录。换句话说,我需要一个在2012 年工作但不是在2011 年工作的员工列表。我不知道为什么我不能这样做!如果您理解问题,请跳过下面的 Java 代码。
如果我用 Java 解析员工表,它会是:
// This is what is returned at the end
List theQueryResults = new List();
// This would be all employees and the years they worked, assume it's filled.
Table employees = new Table (int employeeID, int year);
for (int i = 0; i < employees.count(); i++) {
boolean addToQuery = false;
for (int j = 0; j < employees[0].length; j++) {
if ( theArray[i][j] == 2011) {
addToQuery = false;
break;
}
if ( theArray[i][j] == 2012) { addToQuery = true; }
}
if (addToQuery == true) { theQueryResults.add(employees[i].id); }
}
我将不胜感激。我脑子有问题。
【问题讨论】:
标签: sql if-statement