合并重复数值

huangapple go评论55阅读模式
英文:

Add up the duplicate values

问题

我想知道每小时的推文总数,但它给我重复的数据。

想要的结果如下:

| 每小时推文数 | 总推文数 |
| ------------ | -------------- |
| 11           | 31             |
| 12           | 27            |
英文:

I want to know the total number of tweets by the hour but it gives me duplicates.

SELECT DISTINCT datepart(hh,tweet_created) AS hours_tweeted, COUNT(tweet_text) AS total_tweets
FROM [New_years_resolutions_2020]
GROUP BY tweet_created
ORDER BY total_tweets DESC;
hours_tweeted total_tweets
11 16
11 15
12 14
12 13

I want something like this

hours_tweeted total_tweets
11 31
12 27

答案1

得分: 0

你可以尝试以下查询以获得所需结果

选择 datepart(hh, tweet_created) 作为 hours_tweeted, COUNT(DISTINCT tweet_text) 作为 total_tweets
从 [新年愿望_2020]
按 datepart(hh, tweet_created) 分组
按 total_tweets 降序排序;
英文:

You can try this query to get the desired result

SELECT datepart(hh, tweet_created) AS hours_tweeted, COUNT(DISTINCT tweet_text) AS total_tweets
FROM [New_years_resolutions_2020]
GROUP BY datepart(hh, tweet_created)
ORDER BY total_tweets DESC;

huangapple
  • 本文由 发表于 2023年3月1日 12:00:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75599459.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定