如何将一个表的总和连接到另一个表?

问题描述

| 如果我有两个表,batchs和batch_log,batchs具有有关特定batch的信息,而batch_log仅具有batch_log记录的id,batch_id和time_elapsed字段如何从另一个具有关系的表的字段中加入总计的batch_log.batch_id = batchs.id,以便我可以获取该批次的所有time_elapsed的总数?     

解决方法

        我可以根据你的问题来解释。   选择总和(time_elapsed),batch_id   从(选择   batchs.batch_id,时间从   批处理,batch_log其中         batches.batch_id = batch_log.batch_id)   按batch_id分组; 希望这可以帮助。     ,        如果您需要SQL查询,这可能对您有帮助: 从批处理b,batch_log bl中选择b.id,sum(time_elapsed) 在哪里b.id = bl.batch_id 按b.id分组