select PI.*,SUM(PP.Power_have) from prod_ps_log_index PI left join Prod_Ps_Log_Plant_Power PP
on PI.Index_Name =PP.PLANT_NAME
where PI.date_type=1
and PI.index_type =2
and PI.year =2009
我想查prod_ps_log_index 表中的所有数据 其中 prod_ps_log_index 表中有一个indexName的字段
Prod_Ps_Log_Plant_Power表有一个 PLANT_NAME 的字段 当 PLANT_NAME = indexName 时(Prod_Ps_Log_Plant_Power表中有多条数据的plantName 与 indexName 相等)计算这些数据的Power_have字段的和 然后座位一条数据 如prod_ps_log_index 表中indexName ='第一电厂'
Prod_Ps_Log_Plant_Power 表中电厂有三条数据 与之对应 如: plantName Power_have
'第一电厂' 432
'第一电厂' 432
'第一电厂' 342 我要的结果就是 prod_ps_log_index的各个字段 和(432+432+342) 帮帮忙啊
on PI.Index_Name =PP.PLANT_NAME
where PI.date_type=1
and PI.index_type =2
and PI.year =2009
我想查prod_ps_log_index 表中的所有数据 其中 prod_ps_log_index 表中有一个indexName的字段
Prod_Ps_Log_Plant_Power表有一个 PLANT_NAME 的字段 当 PLANT_NAME = indexName 时(Prod_Ps_Log_Plant_Power表中有多条数据的plantName 与 indexName 相等)计算这些数据的Power_have字段的和 然后座位一条数据 如prod_ps_log_index 表中indexName ='第一电厂'
Prod_Ps_Log_Plant_Power 表中电厂有三条数据 与之对应 如: plantName Power_have
'第一电厂' 432
'第一电厂' 432
'第一电厂' 342 我要的结果就是 prod_ps_log_index的各个字段 和(432+432+342) 帮帮忙啊
select PI.*,NVL(SUM(PP.Power_have),0) AS TOTAL
from prod_ps_log_index PI,Prod_Ps_Log_Plant_Power PP
where PI.Index_Name =PP.PLANT_NAME and PI.date_type=1
and PI.index_type =2 and PI.year =2009
group by PI.*(此处换成具体的行)
on PI.Index_Name =PP.PLANT_NAME
where PI.date_type=1
and PI.index_type =2
and PI.year =2009
group by PI.*(此处换成具体的行)
from prod_ps_log_index PI
left join Prod_Ps_Log_Plant_Power PP
on PI.Index_Name =PP.PLANT_NAME
where PI.date_type=1
and PI.index_type =2
and PI.year =2009