0

Suppose I have a table with the following fields:

-------------------
Customer      Model 
-------------------
A             abc
B             abc|xyz
C             xyz|cde

How do I count the number of occurrences of abc, xyz, and cde? Thanks!

Samuel
  • 11
  • 1
  • 3
    You should seriously give consideration to _changing_ your data model, such that each pipe-delimited model is on its own row. Avoid storing `|` separated data. – Tim Biegeleisen May 08 '21 at 04:14

1 Answers1

0

SUBSTRING_INDEX is your friend. You can compare it with a query like this:

SELECT *
FROM yourTable
WHERE
    SUBSTRING_INDEX( Model , "|", 1) =  "xyz" OR
    SUBSTRING_INDEX( Model , "|", -1) = "xyz";
Bernd Buffen
  • 14,525
  • 2
  • 24
  • 39