Tell me about a time you worked on SQL questions involving if-else logic, window functions, and fraud detection KPIs like recall and precision.
Use the provided transaction and fraud score data to calculate fraud KPIs for every available model threshold. Select the best threshold for each model using F1 score, with precision and recall as supporting metrics.
model_name, threshold, precision, recall, f1_score, and threshold_rank.model_name.fraud_score as a model-specific threshold candidate.fraud_score or NULL actual_fraud.fraud_score >= threshold as the inclusive fraud-prediction condition.precision, recall, and f1_score to 4 decimal places; return NULL when a denominator is zero.threshold, and sort models ascending by model_name.| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| customer_id | INT | Customer associated with the transaction |
| transaction_amount | DECIMAL(12,2) | Transaction amount |
| actual_fraud | BOOLEAN | Confirmed fraud label; NULL means not labeled |
| Column | Type | Description |
|---|---|---|
| score_idPK | INT | Unique model score identifier |
| transaction_id | INT | Transaction scored by the model |
| model_name | VARCHAR(50) | Fraud model name |
| fraud_score | DECIMAL(4,2) | Model fraud probability score |