开发者

How do I join the total of one table to another?

If I have two tables, batches and batch_log, batches has information about a specific batch and batch_log simply has the id of the batch_log record, the batch_开发者_高级运维id and the time_elapsed field how do I join the total from a field in another table that has a relationship of batch_log.batch_id = batches.id so that I can get the total of all of the time_elapsed for that batch?


This is what i can interpret from your question.

select sum(time_elapsed) ,batch_id from (select batches.batch_id,time_elapsed from batches,batch_log where batches.batch_id=batch_log.batch_id ) group by batch_id;

Hope this helps.


If you are in need for a sql query this might help you :

SELECT b.id,sum(time_elapsed) FROM batch b,batch_log bl WHERE b.id=bl.batch_id GROUP BY b.id

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜