The NULLIF function takes two arguments. If the two arguments are equal, then NULL is returned. Otherwise, the first argument is returned.
Table Sales_Data
Store_name | Actual | Goal |
Store A | 50 | 50 |
Store B | 40 | 50 |
Store C | 25 | 30 |
We want to show NULL if actual sales is equal to sales goal, and show actual sales if the two are different. To do this, we issue the following SQL statement:
SELECT Store_name, NULLIF(Actual,Goal) FROM Sales_Data;
The result is:
Store_name | NULLIF(Actual,Goal) |
Store A | NULL |
Store B | 40 |
Store C | 25 |
Stay Tune.
Have a nice day... 'N happy Coding :)
No comments:
Post a Comment