In SQL, how to assign the value of a column to null without using the CASE statement, using the nested NULLIF function when condition A or condition B is met
P粉310754094
P粉310754094 2023-08-25 13:26:01
0
2
527
<p>I have a column C1 whose value can be 'values', 'empty' or 'N/A'. </p> <pre class="brush:php;toolbar:false;">| C1 | ------- | | | N/A | |apple|</pre> <p>I want to select column C1 in a way that converts null values ​​and N/A to NULL, using NULLIF. </p> <pre class="brush:php;toolbar:false;">| C1 | ------- |NULL | |NULL | |apple|</pre> <p>We can use <code>NULLIF(C1, '')</code>, which returns NULL if the column value is empty. </p> <p>We can also use CASE to achieve these two situations, but I want to know if there is a way to use NULLIF to achieve it, and if so, how to achieve it? (Or other methods besides CASE)</p> <p>Similar to <code>NULLIF(C1, '' OR 'N/A')</code></p> <p>Thanks in advance. </p>
P粉310754094
P粉310754094

reply all(2)
P粉253800312

Use caseExpression:

(case when c1 not in ('', 'N/A') then c1 end)
P粉925239921

You can use nested NULLIF() functions to achieve:

NULLIF(NULLIF(c1, ''), 'N/A')

See Demo.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!