I have a table that stores employee names and years they worked. The columns are:
employeeID int NOT NULL,
year int NOT NULL
The primary key is composite: employeeID and year. I need to select all records in the table where the year 2012 exists for that employeeID, but NOT the year 2011. In other words I need a list of employees that worked in 2012, but NOT in 2011. I don’t know why I can’t do this! If you understand the question, skip the Java code below.
If I was to parse a Table of employees in Java it would be:
// 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); }
}
I’d appreciate a response. I’m having a brainfart.
1 Answer