'PHP SQL Case when value like
I am trying to use case when to count the total when the column 'Name' has the value 'apple' in it.
So for example, I have 3 values in my column 'Name'.
hallo (apple), hallo today, hallo (apple)
I am trying to count the result which contains apple and I do not want it in the where part of the statement.
I am trying to accomplish this with the following statement, but I get a SQL error around the like operator. Is what I want possible and if so how do I do it?
SELECT
COUNT(CASE WHEN Name = LIKE '%(apple)%' THEN 1 ELSE null end) AS TotalApples
FROM account WHERE id IN (0,$in)
I expect the result of this query to be 2 as the (apple) is 2 times present in my example.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
