about query1(100分)

  • 主题发起人 主题发起人 yangyj
  • 开始时间 开始时间
Y

yangyj

Unregistered / Unconfirmed
GUEST, unregistred user!
各位朋友:
我要写一sql server 7.0 之查询:
select pjcb=round(sum(sail_total_day*b.carrypower)/天数之和day,1)
from shipdata a,shipqh b
where nianyue>=:nianyue1 and nianyue<=:nianyue2
其中:nianyue为表shipdata的字段,类型:char(6),含义:年月.
例如:nianyue>=‘199908’ and nianyue<=‘199912’
我的目的:根据参数:nianyue1和:nianyue2来写'天数之和day'.
例如:当nianyue1=‘199908’,nianyue2=‘199912时,
天数之和day=153天
请各位帮忙。谢谢!

 
试试:
select pjcb=round(sum(sail_total_day*b.carrypower)/(
datediff(dd,convert(char(6),:nianyue4,12),convert(char(6),:nianyue1,12),1)
from shipdata a,shipqh b
where nianyue>=:nianyue1 and nianyue<=:nianyue2
 
select pjcb=round(sum(sail_total_day*b.carrypower)/
datediff(dd,convert(char(6),:nianyue3,12),convert(char(6),:nianyue4,12)),1)
from shipdata a,shipqh b
where nianyue>=:nianyue1 and nianyue<=:nianyue2

注意:
nianyue4>nianyue3
 
'天数之和day'只和:nianyue1和:nianyue2有关,
且nianyue>=:nianyue1,nianyue<=:nianyue2
 
其实就是你将付给nianyue1也付给nianyue3,付给nianyue2也付给nianyue4!!
 
select pjcb=round(sum(sail_total_day*b.carrypower)/
datediff(dd,convert(char(6),:nianyue1,12),convert(char(6),:212)),1)
from shipdata a,shipqh b where nianyue>=:nianyue1 and nianyue<=:nianyue2
这样只可以吗?这样只要两个参数。
 
select pjcb=round(sum(sail_total_day*b.carrypower)/
datediff(dd,convert(char(6),:nianyue1,12),convert(char(6),:nianyue2)),1)
from shipdata a,shipqh b where nianyue>=:nianyue1 and nianyue<=:nianyue2
这样可以吗?这样只要两个参数。
 
Delphi好象不支持这样,以前有人问过此问题,不过也没关系嘛,不就是多两次付值。
 
谢谢沈前卫:
select pjcb=datediff(dy,convert(char(6),:nianyue1)+'01',
convert(char(6),:nianyue2)+'01')
from shipdata a,shipqh b
where nianyue>=:nianyue1 and nianyue<=:nianyue2
这样可以,只要两个参数,但要保证:nianyue2>nianyue1

另:
begin
s1:='2000-03-10';
d1:=strtodate(s1);
d2:=date();
//今天日期:'2000-03-28'
day:=d2-d1;
end
我要计算出日期d2和日期d1之间的天数,
day:=d2-d1这行代码要如何修改?请各位帮忙,谢谢!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部