-2
id | segment1 |segment2|segment3|segment4|**FREQUENT**
1  | A        | B      | A      | A      | A
2  | B        | C      | C      | C      | C

Need to find the most frequent letters from segment1 |segment2|segment3|segment4| i.e to find column FREQUENT.

30thh
  • 10,861
  • 6
  • 32
  • 42

1 Answers1

0

First of all you need to copy all the segments into a single column. One can do it using UNION or a temporary table.

Then you need to count the frequency grouping the result by ID.

Then you need to get the most frequent value in every group. It can be done using self joining over LEFT JOIN or using ordering and row numbering by group. It is the most complicated part. See

Row number per group in mysql

Then you filter by the row number and enjoy the result.

30thh
  • 10,861
  • 6
  • 32
  • 42