日期:2014-05-18  浏览次数:20782 次

如何算出一张表中相同ID中的其它字段的和?急急急!!!!!!!!!!!!
例如:下面的一张表:表名是dlsc.fkds_day

DATADATE       STANTION_ID FKDS KHDS
2007-9-1       16800                   1 1
2007-9-2       16800                   2 2
2007-9-3       18900                   3 3
2007-9-4       18900                   4 4

我要通过这个字段STANTION_ID相同的ID(例如;16800)算出表dlsc.fkds_day中字段FKDS的和,表dlsc.fkds_day中字段KHDS的和。具体应该怎么实现啊???该如何写啊???
非常的感谢各位朋友!

------解决方案--------------------
select sum(FKDS),sum(KHDS) from fkds_day group by STANTION_ID
------解决方案--------------------
select a.*,b.ZZMC
from (
select STANTION_ID,sum(FKDS) as fkds,sum(KHDS) as khds
from fkds_day
group by STANTION_ID) a left join gzxt.zzjg b
on a.STANTION_ID=b.BMDM
没时间调,差不多语句是这样的,自己调调试试吧
------解决方案--------------------
select zzjg.ZZMC,sum(fkds_day.FKDS),sum(fkds_day.KHDS)
from fkds_day,zzjg
where fkds_day.STANTION_ID=zzjg.BMDM
group by zzjg.ZZMC

不知道这样可不可以.
------解决方案--------------------
求单个:
select sun(FKDSKHDS) from fkds_day where STANTION_ID = '16800 '
求一个组:
select sun(FKDSKHDS) from fkds_day group by STANTION_ID