SQL Challenges-1: Convert negative numbers to positive and vice verse
From the following table, write a SQL query to convert negative numbers to positive and vice verse. Return the number.
Input:
Table: tablefortest
Structure:
Field | Type | Null | Key | Default | Extra |
---|---|---|---|---|---|
srno | int(11) | YES | |||
pos_neg_val | int(11) | YES |
Data:
srno | pos_neg_val |
---|---|
1 | 56 |
2 | -74 |
3 | 15 |
4 | -51 |
5 | -9 |
6 | 32 |
Sample Solution:
SQL Code(MySQL):
Sample Output:
srno|pos_neg_val|converted_signed_value| ----|-----------|----------------------| 1| 56| -56| 2| -74| 74| 3| 15| -15| 4| -51| 51| 5| -9| 9| 6| 32| -32|
SQL Code Editor:
Contribute your code and comments through Disqus.
Previous: Find active customers.
Next: Century of a given date.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics