Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Bagaimana cara menghitung kemunculan di kolom yang dipisahkan koma?

Anda dapat menggunakan:

SqlFiddleDemo

SELECT sub.val AS tags, COUNT(*) AS `count`
FROM
(
  SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(t.tags, ',', n.n), ',', -1) AS val
  FROM tab t 
  CROSS JOIN 
  (
     SELECT a.N + b.N * 10 + 1 n
       FROM 
      (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a
      ,(SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) b
      ORDER BY n
  ) n
  WHERE n.n <= 1 + (LENGTH(t.tags) - LENGTH(REPLACE(t.tags, ',', '')))
) sub
GROUP BY sub.val


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Indeks tidak terdefinisi:REMOTE_ADDR saat Laravel bermigrasi

  2. Bisakah kueri MySQL mengubah baris menjadi kolom?

  3. Laravel Fasih dengan()-> mengembalikan null

  4. Mata Uang Kripto Tipe Data MySQL ?

  5. Python, Konversi 9 Tuple tanggal UTC ke format datetime MySQL