Write a SQL query to solve a classic 2-sum problem on a dataset with repeated values.
Treat each row as a distinct element, so equal numeric values from different rows may form a valid pair. Return every pair of distinct rows whose values sum to a target, excluding null values and targets without a matching pair.
target_value, first_value_id, second_value_id, first_value, second_valuetarget_value, then first_value_id, then second_value_id ascending| Column | Type | Description |
|---|---|---|
| value_idPK | INT | Unique identifier for an input row |
| number_value | INT | Numeric value used in pair calculations |
| Column | Type | Description |
|---|---|---|
| target_idPK | INT | Unique identifier for a target |
| target_value | INT | Required sum for a matching pair |