且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

mysql 计数总计来自具有逗号分隔值的字段

更新时间:2023-01-31 14:49:44

检查这个我用过 Postgresql,有id"、comma_sep_string"列和表名string_comma",当有计数时它会显示该记录,如果计数为零,则不会显示该特定记录并查看给定查询输出的屏幕截图

Check this i've used Postgresql, having "id", "comma_sep_string" columns with table name "string_comma", when there is a count it'll show that record and if count is zero it'll not show that particular record and see the screenshot for the output of the given query

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