Mysql
 sql >> Database >  >> RDS >> Mysql

mysql conteggio totale da un campo con valori separati da virgole

Controlla questo ho usato Postgresql, con colonne "id", "comma_sep_string" con il nome della tabella "string_comma", quando c'è un conteggio mostrerà quel record e se count è zero non mostrerà quel particolare record e vedrai lo screenshot per l'output della query data

select temp1.id, temp1.comma_sep_string, sum(count) from
(select temp.id, temp.comma_sep_string, temp.years, count(*) as count
from
(SELECT
ID, comma_sep_string,
regexp_split_to_table(comma_sep_string, E',') AS years
FROM string_comma) as  temp
where temp.years::int > 1980
group by temp.id, temp.years, temp.comma_sep_string) as temp1
group by temp1.id, temp1.comma_sep_string