Round #657
10 May 2026, 08:33· csharp· qwen2.5-coder-7b-instruct· r13-clean-hints
- Complexity
- band 1
- ZP / UO / OBS
- 6 / 4 / 1
- Journey weight
- 602
- Lightshift ΔL
- —
Prompt
Write a SQL query that returns customers with more than 3 orders.
Zero-point index (what the engine surfaced)
ZPI-ZPI-0006 | 2026-05-10T08:33:16Z
Write a SQL query that returns customers with more than 3 orders.
ZERO POINT — 6 entries (structural invariants)
● hsl(27.69, 100%, 50%) async [feature]
● hsl(145.64, 100%, 50%) Task of T [feature]
● hsl(348.72, 100%, 36%) IDisposable [feature]
● hsl(7.18, 100%, 50%) class [feature]
● hsl(0.00, 100%, 50%) public [feature]
● hsl(84.10, 100%, 50%) namespace [feature]
UNOBSERVED — 4 entries (implied truths)
○ hsl(9.23, 100%, 50%) interface [feature]
○ hsl(180.92, 100%, 28%) Database health check [function]
○ hsl(144.00, 100%, 42%) Connection resilience [function]
○ hsl(83.08, 100%, 42%) ILogger of T injection [function]
OBSERVED — 1 entries (explicit in request)
◉ hsl(98.46, 100%, 50%) with [feature]
COMPLEXITY │ 11 entries │ spread: 172° │ band: MEDIUM
Baseline response (no ZPI)
To write an SQL query that returns customers who have placed more than 3 orders, you need to assume that there is a table named `Orders` which contains information about each order, including the customer ID (`CustomerID`). Here's how you can structure the query:
```sql
SELECT CustomerID, COUNT(*) AS OrderCount
FROM Orders
GROUP BY CustomerID
HAVING COUNT(*) > 3;
```
### Explanation:
- **SELECT CustomerID, COUNT(*) AS OrderCount**: This part selects the `CustomerID` and counts the number of orders for each customer. The count is aliased as `OrderCount`.
- **FROM Orders**: Specifies the table from which to retrieve data.
- **GROUP BY CustomerID**: Groups the results by `CustomerID`, so that the count is calculated for each individual customer.
- **HAVING COUNT(*) > 3**: Filters the groups to include only those where the number of orders (`OrderCount`) is greater than 3.
### Example:
If your `Orders` table looks like this:
| OrderID | CustomerID |
|---------|------------|
| 1 | A |
| 2 | B |
| 3 | A |
| 4 | C |
| 5 | A |
| 6 | D |
The query will return:
| CustomerID | OrderCount |
|------------|------------|
| A | 3 |
This indicates that customer `A` has placed more than 3 orders.
Enhanced response (with ZPI)
To implement the request, we'll write a SQL query to return customers who have placed more than three orders. We'll assume you're using Entity Framework Core for database operations and dependency injection.
Here's the complete code:
```csharp
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
public class CustomerOrderContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
public DbSet<Order> Orders { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Configure your database connection string here
optionsBuilder.UseSqlServer("YourConnectionStringHere");
}
}
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Order> Orders { get; set; } = new List<Order>();
}
public class Order
{
public int Id { get; set; }
public int CustomerId { get; set; }
public Customer Customer { get; set; }
}
public interface ICustomerOrderService
{
Task<List<Customer>> GetCustomersWithMoreThanThreeOrdersAsync();
}
public class CustomerOrderService : ICustomerOrderService
{
private readonly CustomerOrderContext _context;
public CustomerOrderService(CustomerOrderContext context)
{
_context = context;
}
public async Task<List<Customer>> GetCustomersWithMoreThanThreeOrdersAsync()
{
var query = from customer in _context.Customers
join order in _context.Orders on customer.Id equals order.CustomerId
group order by customer into g
where g.Count() > 3
select g.Key;
return await query.ToListAsync();
}
}
public class Program
{
public static async Task Main(string[] args)
{
using (var context = new CustomerOrderContext())
{
var service = new CustomerOrderService(context);
var customersWithMoreThanThreeOrders = await service.GetCustomersWithMoreThanThreeOrdersAsync();
foreach (var customer in customersWithMoreThanThreeOrders)
{
Console.WriteLine($"Customer: {customer.Name}");
}
}
}
}
```
### Explanation:
1. **Database Context (`CustomerOrderContext`)**:
- This class inherits from `DbContext` and defines the DbSets for `Customers` and `Orders`.
2. **Entities (`Customer` and `Order`)**:
- These classes represent the entities in your database.
- The `Customer` entity has a collection of `Order` entities.
3. **Service Interface (`ICustomerOrderService`)**:
- This interface defines a method to retrieve customers with more than three orders.
4. **Service Implementation (`CustomerOrderService`)**:
- This class implements the service interface.
- It uses Entity Framework Core to execute a LINQ query that joins `Customers` and `Orders`, groups them by customer, filters for those with more than three orders, and selects the customers.
5. **Program Class**:
- The `Main` method demonstrates how to use the service to retrieve and print customers with more than three orders.
### Dependency Injection (DI) Registration:
If you're using a dependency injection container like Microsoft.Extensions.DependencyInjection, you can register the service as follows:
```csharp
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
public class Program
{
public static async Task Main(string[] args)
{
var services = new ServiceCollection();
services.AddDbContext<CustomerOrderContext>(options =>
options.UseSqlServer("YourConnectionStringHere"));
services.AddScoped<ICustomerOrderService, CustomerOrderService>();
var serviceProvider = services.BuildServiceProvider();
using (var scope = serviceProvider.CreateScope())
{
var service = scope.ServiceProvider.GetRequiredService<ICustomerOrderService>();
var customersWithMoreThanThreeOrders = await service.GetCustomersWithMoreThanThreeOrdersAsync();
foreach (var customer in customersWithMoreThanThreeOrders)
{
Console.WriteLine($"Customer: {customer.Name}");
}
}
}
}
```
This setup ensures that the `CustomerOrderContext` and `CustomerOrderService` are properly registered for dependency injection, making it easier to manage dependencies and test the service.
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.