根据情感SQL计算提及次数 [英] Counting the number of mention depending on sentiment SQL

查看:29
本文介绍了根据情感SQL计算提及次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果这是任何内容的重复,我没有找到特别能满足我想要的答案.

Apologies if this is a duplicate of anything, I wasn't finding answers which particularly did what I wanted.

我正在尝试编写一个SQL查询,该查询将返回对数据集中的一个候选对象包含肯定,否定或中性情绪的行数.

I'm trying to write a SQL query which will return the count of rows which contain a positive, negative or neutral sentiment on one of the candidates in the dataset.

这是供参考的屏幕截图

情感是一列,但其中的值将推文定义为正,负或中性.我的目标是让查询返回类似这样的内容

Sentiment is one column but the values in it define the tweet to be positive, negative, or neutral. my goal is to have the query return something like this

如果有人可以举一个例子说明这一点,我将不胜感激!

if anyone could give me an example on how to do this, I'd appreciate!

推荐答案

尝试像这样在查询中使用特定的COUNT()函数.

try using specific COUNT() functions in your query like this.

SELECT name as `Candidate Name`, 
    COUNT(CASE WHEN sentiment='Negative' THEN 1 END) AS `Negative`,
    COUNT(CASE WHEN sentiment='Positive' THEN 1 END) AS `Positive`,
    COUNT(CASE WHEN sentiment='Neutral' THEN 1 END) AS `Neutral`,
    COUNT(*) AS `Total`

FROM [table]
    
GROUP BY candidate

这篇关于根据情感SQL计算提及次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆