0

I'm currently having a table filled with likes and tweets of a certain post sorted on date.

I want to know the query to count the total of likes and tweets sorted by post_id. The result of the example below should be 50 likes and 20 tweets.

The structure of the table is:

post_id date    likes   tweets
1   2012-06-09  20  10
1   2012-06-10  30  10
3
  • 3
    Review the aggregate functions This is a rudimentary SUM(likes), SUM(tweets) GROUP BY post_id Commented Jun 10, 2012 at 14:26
  • What is your table structure and what have you tried so far? Commented Jun 10, 2012 at 14:26
  • vote answers and choose best answer if it was working 4u Commented Jun 10, 2012 at 14:30

2 Answers 2

3

Have a look at this doc. Try this:

SELECT SUM(`likes`) AS `likes`, SUM(`tweets`) AS `tweets` FROM `table` GROUP BY `post_id`
Sign up to request clarification or add additional context in comments.

Comments

0

In your case:

your table name assumed: tweets

select SUM(likes), SUM(tweet) from post_table group by(post_id)

General Form:

SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name 

1 Comment

He wanted the sum of both likes and tweets, this is just summing likes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.