现在我有三个表。。oilstationteam a,oilpost_stat b,backcandaystat c.现在要取三个表里的数据(取三个字段即可)a.gowordnum,b.liter_total1,c.oilbackliter.三个表对应的其中三个字段要相等才可以:a.nodeno=b.nodeno=c.nodeno,convert(char(10),a.opedate,111)=convert(char(10),b.opedate,111)=convert(char(10),c.accountdate,111).但其中的a表,,是要对相同的oilno统计一个数的和sum(a.gowordnum)
我是这样子写的。。
select a.gowordnum,b.liter_total1,c.oilbackliter from oilstationteam a,oilpost_stat b,backcandaystat c
where a.nodeno=b.nodeno and a.nodeno=c.nodeno and convert(char(10),a.opedate,111)=convert(char(10),b.opedate,111) and convert(char(10),a.opedate,111)=convert(char(10),c.accountdate,111) and a.oilno=b.oilno and a.oilno=c.oilno and a.nodeno='14000697' and convert(char(10),a.opedate,111)='2006/10/14'
得结果
gowordnum liter_total1 oilbackliter
------------------ --------------- ---------------
1514.64 2802.97 40.00
1328.33 2802.97 40.00
1199.98 1179.98 20.00但这不是我想要的。我想要的应是那个40的。。1514.64+1328.33的和。。即应是
gowordnum liter_total1 oilbackliter
------------------ --------------- ---------------
2842.97 2802.97 40.00
1199.98 1179.98 20.00
这才是对的。请高人给解决下。。多谢。
我是这样子写的。。
select a.gowordnum,b.liter_total1,c.oilbackliter from oilstationteam a,oilpost_stat b,backcandaystat c
where a.nodeno=b.nodeno and a.nodeno=c.nodeno and convert(char(10),a.opedate,111)=convert(char(10),b.opedate,111) and convert(char(10),a.opedate,111)=convert(char(10),c.accountdate,111) and a.oilno=b.oilno and a.oilno=c.oilno and a.nodeno='14000697' and convert(char(10),a.opedate,111)='2006/10/14'
得结果
gowordnum liter_total1 oilbackliter
------------------ --------------- ---------------
1514.64 2802.97 40.00
1328.33 2802.97 40.00
1199.98 1179.98 20.00但这不是我想要的。我想要的应是那个40的。。1514.64+1328.33的和。。即应是
gowordnum liter_total1 oilbackliter
------------------ --------------- ---------------
2842.97 2802.97 40.00
1199.98 1179.98 20.00
这才是对的。请高人给解决下。。多谢。
解决方案 »
- dll中动态添加的flash.ocx如何释放?
- 请教一下,关于delphi报表方面,好像有个*.grd的文件好像很好用的样子,有人知道这是什么吗?
- 请问delphi怎么响应atl的连接点事件
- 如何使某目录不能被删除?
- jackie168兄弟请进, 我想要的象棋源码, 分不够可以提. 谢谢
- <<<<<<< 线程高手请进!我向你们拜师!
- delphi文件读取和写入问题
- 还是画图的问题
- 为什么我加载一个自己写的DLL时会报cannot create application object in a shared object or library
- 请问,怎么确定A驱中是否有软盘
- webservices 的发布问题!
- 关于Float转INT的问题?
我一般采用算法分析,而不是单纯的SQL语句~
Select gowordnum=sum(a.gowordnum),b.liter_total1,c.oilbackliter
from oilstationteam a,oilpost_stat b,backcandaystat c
where a.nodeno=b.nodeno and a.nodeno=c.nodeno and
a.oilno=b.oilno and a.oilno=c.oilno and a.nodeno='14000697' and
convert(char(10),a.opedate,111)='2006/10/14' and
Datediff(day,a.opedate,b.opedate)=0 and Datediff(day,a.opedate,c.accountdate)=0
group by b.liter_total1,c.oilbackliter
这是你写的:
select a.gowordnum,b.liter_total1,c.oilbackliter
into #t //加一个一行 ,临时表
from oilstationteam a,oilpost_stat b,backcandaystat c
where a.nodeno=b.nodeno and a.nodeno=c.nodeno and convert(char(10),a.opedate,111)=convert(char(10),b.opedate,111) and convert(char(10),a.opedate,111)=convert(char(10),c.accountdate,111) and a.oilno=b.oilno and a.oilno=c.oilno and a.nodeno='14000697' and convert(char(10),a.opedate,111)='2006/10/14'
这个时候如果你select *From #t 就会得到你上面不要的那个结果,下面再处理一下
select sum(gowordnum),sum(liter_total1),oilbackliter from #t group by oilbackliter
就得到你要的结果了,当然了,我这是偷懒的办法,只是由此可以看出,你上面的SQL修改修改也可以实现这样的功能
字段名忘了加,怕你弄错