Skip to main content
Database

Conditional Logic with CASE

QueryValidateMedium

Description

Categorize products by price range (Budget/Mid/Premium).

Test Scenario

-- Your query:
SELECT name, price,
  CASE
    WHEN price < 50 THEN 'Budget'
    WHEN price < 100 THEN 'Mid-range'
    ELSE 'Premium'
  END as price_tier
FROM products;

-- Expected: Products with price tier labels

Testing Tips

  • •CASE WHEN provides if-else logic
  • •ELSE handles default case
  • •END closes the CASE block
// Playwright API Testing - Database
import { test, expect } from '@playwright/test';
test('Database query via API', async ({ request }) => {
const response = await request.post('/api/database/query', {
data: {
sql: 'SELECT * FROM users WHERE id = ?',
params: [1]
}
});
expect(response.ok()).toBeTruthy();
const { rows } = await response.json();
expect(rows.length).toBeGreaterThan(0);
});

Challenge ID: sql-case-when

2 frameworks available