Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading