MySQL印地语字符转义及Google Sheets SQL过滤印地语数据求助
解决MySQL过滤印地语条目并同步到Google Sheets的问题
看起来你已经搞定了MySQL到Google Sheets的数据同步,但卡在了筛选印地语内容这一步。针对你的需求,我们可以通过在SQL查询中添加印地语字符匹配条件来实现过滤,下面是具体的调整方案:
核心思路:用正则匹配印地语Unicode范围
印地语字符的Unicode编码范围是U+0900到U+097F,我们可以利用MySQL的REGEXP语法在WHERE子句中筛选包含这些字符的条目。
修改后的完整SQL查询
假设你的表中有存储印地语内容的字段(比如article_title或content),将下面的查询中的article_title替换为你实际使用的字段即可:
select property, week, sum(Original_Stories) "Original Stories", sum(Wire_Stories) "Wire Stories", sum(Photo_Gallery) "Photo Gallery", sum(Video_Gallery) "Video Gallery" from ( select *, case when a= "Original_Stories" then total end as "Original_Stories", case when a= "Wire" then total end as "Wire_Stories", case when a= "Photo" then total end as "Photo_Gallery", case when a= "Video_Gallery" then total end as "Video_Gallery" from ( select "Zee Hin" as property, yearweek(date_format(date_published,"%Y-%m-%d"),6) week, case when ((article_type like 'live_blog') or (article_type like '%article%' and agency_name like 'ज़ी न्यूज़ डेस्क') or (article_type like '%article%' and agency_name like 'एक्सक्लूसिव') or (article_type like '%article%' and agency_name like 'ज़ी मीडिया ब्यूरो') or (article_type like '%article%' and agency_name like 'Exclusive')) then "Original_Stories" when (article_type like '%gallery%') then "Photo" when (article_type like '%video%') then "Video_Gallery" else 'Wire' end as a, count(distinct article_id) total, count(distinct date_format(date_published, "%Y-%m-%d")) days from zeenews_hindi where date_format(date_published, "%Y-%m-%d") >= '2018-12-30' -- 关键:添加印地语字符匹配条件 AND article_title REGEXP '[\x{0900}-\x{097F}]' group by 2,3 ) temp ) agg group by 1,2
重要注意事项
- 字段替换:一定要把
article_title换成你表中实际存储印地语内容的字段(比如文章正文、标题等)。 - 字符集检查:确保你的
zeenews_hindi表和目标字段使用的是utf8mb4字符集(支持完整Unicode),否则正则匹配可能失效。可以用以下命令查看或修改字段字符集:-- 查看表结构和字符集 SHOW CREATE TABLE zeenews_hindi; -- 修改字段为utf8mb4字符集(示例) ALTER TABLE zeenews_hindi MODIFY COLUMN article_title TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - MySQL版本兼容:如果使用MySQL 5.7及以下版本,旧版本对Unicode正则的支持有限,可能需要改用
REGEXP BINARY或者调整正则写法,比如:AND article_title REGEXP BINARY '[\u0900-\u097F]'
把这个修改后的SQL替换你原来的查询,再同步到Google Sheets,就能得到过滤后的印地语条目统计了。
内容的提问来源于stack exchange,提问作者Harshit Agarwal
相关产品推荐
相关产品推荐

