I have this query
SELECT
COUNT(
CASE
WHEN restricted LIKE '%us%' THEN 2
ELSE 1
END) AS totalcount
FROM
reviews
WHERE
restricted LIKE '%us%'
This counts the total number of values like “us” appearing in a column (restricted). This column is filled by values from a muultiselect checkbox in this “unusual” manner:
*us*ca*uk* etc.
And this works. No problem.
Now, I need to count where this value (us) is NOT appearing.
I tried to do this, a “classic”.
SELECT
COUNT(
CASE
WHEN restricted NOT LIKE '%us%' THEN 2
ELSE 1
END
) AS totalcount
FROM
reviews
WHERE
restricted NOT LIKE '%us%'
I have declared the statemenent NOT LIKE but now… the problem… it count also rows where ‘restricted’ column is NOT FILLED (some listings don’t use this column). And the count is wrong.
Can anyone help, please?
empty value or null value on ‘restricted’ column will pass “restricted NOT LIKE ‘%us%’
” statement. try change to: