İ have a video table named videos and here these are the columns :
vid v_uid v_view v_title v_info
1 45 56487 foo foo
2 45 455
3 45 98989
...
My condition will be " where v_uid = 45 " and i want to 开发者_如何学Goget rows belongs to this id "45" and sum this users video views as total views.
thanks.
I read the question as you want to get all rows and a sum of those rows in one query.
You could do this all in one hit using WITH ROLLUP, e.g.
select *,sum(v_view) as total from videos
where v_uid=45
group by vid with rollup;
Bit hacky, as we don't really need the group by (which is why I'm grouping on the row id vid). What you'll end up with all the individual rows, and a final row with the total sum in it (it will have a NULL vid too, which might help identify it)
If you just want a sum of the views, then you can execute something much simpler
select sum(v_view) as total from videos where v_uid=45;
精彩评论