how can I add up the duplicate values in SQL?

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

>Solution :

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;

Leave a Reply