Reputation: 1411
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
Upvotes: 0
Views: 104
Reputation: 2014
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
Upvotes: 0
Reputation: 1783
Have a look at this doc. Try this:
SELECT SUM(`likes`) AS `likes`, SUM(`tweets`) AS `tweets` FROM `table` GROUP BY `post_id`
Upvotes: 3