Round #656
10 May 2026, 08:32· csharp· qwen2.5-coder-7b-instruct· r13-clean-hints
- Complexity
- band 0
- ZP / UO / OBS
- 0 / 0 / 0
- Journey weight
- 0
- Lightshift ΔL
- —
Prompt
Find the second-highest salary in an employees table.
Zero-point index (what the engine surfaced)
ZPI-ZPI-0005 | 2026-05-10T08:32:48Z
Find the second-highest salary in an employees table.
ZERO POINT — 0 entries (structural invariants)
UNOBSERVED — 0 entries (implied truths)
OBSERVED — 0 entries (explicit in request)
COMPLEXITY │ 0 entries │ spread: 0° │ band: LOW
Baseline response (no ZPI)
To find the second-highest salary in an `employees` table, you can use SQL to query the database. Assuming your `employees` table has a column named `salary`, here is how you can write the SQL query:
```sql
SELECT MAX(salary) AS SecondHighestSalary
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
```
This query works as follows:
1. The inner subquery `(SELECT MAX(salary) FROM employees)` finds the highest salary in the `employees` table.
2. The outer query then selects the maximum salary that is less than this highest salary, effectively giving you the second-highest salary.
If there are multiple employees with the same highest salary and you want to ensure that the result is unique, you can use a subquery to handle this:
```sql
SELECT MAX(salary) AS SecondHighestSalary
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees)
AND salary <> (SELECT MAX(salary) FROM employees);
```
This ensures that if there are multiple highest salaries, the query will still return a unique second-highest salary.
If you need to implement this in C#, you can use ADO.NET or Entity Framework to execute this SQL query and retrieve the result. Here is an example using ADO.NET:
```csharp
using System;
using System.Data.SqlClient;
class Program
{
static void Main()
{
string connectionString = "your_connection_string_here";
string query = @"
SELECT MAX(salary) AS SecondHighestSalary
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees)";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(query, connection);
connection.Open();
object result = command.ExecuteScalar();
if (result != DBNull.Value)
{
int secondHighestSalary = Convert.ToInt32(result);
Console.WriteLine("Second-highest salary: " + secondHighestSalary);
}
else
{
Console.WriteLine("No second-highest salary found.");
}
}
}
}
```
Make sure to replace `"your_connection_string_here"` with your actual database connection string. This code will execute the SQL query and print the second-highest salary to the console.
Enhanced response (with ZPI)
To find the second-highest salary in an `employees` table, you can use SQL to query the database directly. Below is a complete example using C# and Entity Framework Core (EF Core) for data access.
### Step 1: Define the Entity
First, define an entity class that represents the `employees` table:
```csharp
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Salary { get; set; }
}
```
### Step 2: Set Up Entity Framework Core
Next, configure EF Core to connect to your database. This involves creating a DbContext:
```csharp
using Microsoft.EntityFrameworkCore;
public class AppDbContext : DbContext
{
public DbSet<Employee> Employees { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Replace with your actual connection string
optionsBuilder.UseSqlServer("YourConnectionStringHere");
}
}
```
### Step 3: Implement the Query
Now, implement a method to find the second-highest salary:
```csharp
using System;
using System.Linq;
public class EmployeeService
{
private readonly AppDbContext _context;
public EmployeeService(AppDbContext context)
{
_context = context;
}
public decimal? GetSecondHighestSalary()
{
try
{
// Use a subquery to find the highest salary and then exclude it from the main query
var highestSalary = _context.Employees.Max(e => e.Salary);
return _context.Employees.Where(e => e.Salary < highestSalary).Max(e => e.Salary);
}
catch (InvalidOperationException)
{
// If there are no employees or only one employee, return null
return null;
}
}
}
```
### Step 4: Register the Service with Dependency Injection
Finally, register the `EmployeeService` with your dependency injection container:
```csharp
using Microsoft.Extensions.DependencyInjection;
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Add DbContext and other services
services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer("YourConnectionStringHere"));
services.AddScoped<EmployeeService>();
}
}
```
### Explanation
1. **Entity Definition**: The `Employee` class represents the structure of a row in the `employees` table.
2. **DbContext Configuration**: The `AppDbContext` class is configured to connect to the database using Entity Framework Core.
3. **Query Implementation**: The `GetSecondHighestSalary` method uses LINQ to find the second-highest salary. It first finds the highest salary and then excludes it from the main query to find the next highest salary.
4. **Error Handling**: The method handles cases where there are no employees or only one employee by returning `null`.
5. **Dependency Injection**: The `EmployeeService` is registered with the dependency injection container, making it easy to inject into other parts of your application.
This approach ensures that you can find the second-highest salary efficiently and handle potential edge cases gracefully.
Grader chain
Each grader reads the same baseline + enhanced pair and casts an independent verdict. Disagreement is the framework's own signal — not noise to be averaged away.
V1samba/Meta-Llama-3.3-70B-Instruct
BetterV4qwen2.5-coder-3b-instruct
BetterV5openrouter/qwen/qwen3-235b-a22b-2507
BetterV7qwen2.5-coder-7b-instruct
BetterV8openai/gpt-4.1
BetterV9anthropic/claude-opus-4-7
BetterV12openai/gpt-4o
BetterComments
Our grader said what it said. What do you say? Comment as a guest below.
No comments yet. Be the first to say what you make of this round.