你的问题的关键在于求总共应付、已付、未付,日期条件判断比较这里我就不写了:select 总共应付=(a.已付+a.未付),a.已付,a.未付 from (select 已付=Isnull(sum(已付),0),未付=IsNull(sum(未付),0) from table where 你的日期比较条件) a
erickleung() 老兄的Where字句只是两时间段的年相同时成立,建议改为: where 帐单日期-年*100+帐单日期-月>=P1*100+P2 and 帐单日期-年*帐单日期-月 <=p3*100+P4
to:renzhm(戴尔飞) 我想问一下,你的: (select 已付=Isnull(sum(已付),0),未付=IsNull(sum(未付),0) from table 这句语句里,sum(已付)。是不是应该是‘sum(是否已付)’,呀!不然我发现好象没用到‘是否已付’这个字段呀。
to:erickleung() 我用了你的方法写的: procedure TForm1.Button1Click(Sender: TObject); begin query1.Close; query1.SQL.Clear; query1.SQL.Add('select count(*) //这句就有错呀 sum(iif(bl_HavePaid=true,1,0)) as 已付, sum(iif(bl_HavePaid=false,1,0)) as 未付 from 表 where 帐单日期-年>= :p1 and 帐单日期-年<= :p2 and 帐单日期-月 >=:p3 and 帐单日期-月 <=:p4'); query1.ParamByName('p1')=StrToInt(copy(edit1.text,1,4)); query1.ParamByName('p2')=StrToInt(copy(edit2.text,1,4)); query1.ParamByName('p3')=StrToInt(copy(edit1.text,6,2)); query1.ParamByName('p4')=StrToInt(copy(edit2.text,6,2)); end;
to:erickleung() 对不起刚才的问题解决了,现在我想问一下我的日期这样赋值对吗??
总共应付 100 已付 60 未付 40 60 和40 是怎么来的,你还应该有个放数字的栏位吧(假设叫Qty)。 假设你的TABLE叫tb, select sum(a.qty) as 总共应付,sum(b.qty)as 已付,sum(c.qty)as 未付 from tb a,tb b,tb c where a.是否已付<>null and b.是否已付='已付' and c.是否已付='未付' and 日期条件...
to:erickleung() 时间方面的赋值我已经确定没错了,但你的代码中 select count(*) sum(iif(是否已付='已付',1,0)) as 已付, sum(iif(是否已付='未付',1,0)) as 未付系统提示‘sum(iif(是否已付='已付',1,0)) as 已付,’附近有语法错误呀!
谢谢你的回答,你只有1张表呀!
sum(iif(是否已付='已付',1,0)) as 已付,
sum(iif(是否已付='未付',1,0)) as 未付
from 表
where 帐单日期-年 >= :P1
and 帐单日期-年 < :P2
and 帐单日期-月 >= ;p3
and 帐单日期-月 < :p4其中 p1 = StrToInt(copy(edit1.text,1,4))
p2 = StrToInt(copy(edit2.text,1,4))
p3 = StrToInt(copy(edit1.text,6,2))
p4 = StrToInt(copy(edit2.text,6.2))
刚才打错了,我只有1张表呀,没有Table b,和Table c是不是我的题意写的不明白呀!
from (select 已付=Isnull(sum(已付),0),未付=IsNull(sum(未付),0) from table where 你的日期比较条件) a
where 帐单日期-年*100+帐单日期-月>=P1*100+P2
and 帐单日期-年*帐单日期-月 <=p3*100+P4
我想问一下,你的:
(select 已付=Isnull(sum(已付),0),未付=IsNull(sum(未付),0) from table
这句语句里,sum(已付)。是不是应该是‘sum(是否已付)’,呀!不然我发现好象没用到‘是否已付’这个字段呀。
我用了你的方法写的:
procedure TForm1.Button1Click(Sender: TObject);
begin query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select count(*) //这句就有错呀
sum(iif(bl_HavePaid=true,1,0)) as 已付,
sum(iif(bl_HavePaid=false,1,0)) as 未付
from 表
where 帐单日期-年>= :p1
and 帐单日期-年<= :p2
and 帐单日期-月 >=:p3
and 帐单日期-月 <=:p4');
query1.ParamByName('p1')=StrToInt(copy(edit1.text,1,4));
query1.ParamByName('p2')=StrToInt(copy(edit2.text,1,4));
query1.ParamByName('p3')=StrToInt(copy(edit1.text,6,2));
query1.ParamByName('p4')=StrToInt(copy(edit2.text,6,2));
end;
对不起刚才的问题解决了,现在我想问一下我的日期这样赋值对吗??
60 和40 是怎么来的,你还应该有个放数字的栏位吧(假设叫Qty)。
假设你的TABLE叫tb,
select sum(a.qty) as 总共应付,sum(b.qty)as 已付,sum(c.qty)as 未付 from tb a,tb b,tb c
where a.是否已付<>null
and b.是否已付='已付'
and c.是否已付='未付'
and 日期条件...
100 60 40
我只是假设一下,随便写的数字,意思就是 已付+未付=总共应付
表我只有一个。
to :erickleung()
我的日期这样赋值有问题呀,
query1.ParamByName('p1')=StrToInt(copy(edit1.text,1,4));
或
query1.ParamByName('p1')=StrToDate(copy(edit1.text,1,4));
都试了有错呀,不行,该怎么写呀!
我用了
query1.ParamByName('p1').asstring=copy(edit1.text,1,4);
错误是没了,但运行时点BUTTON没数据呀!
STRTODATE
'2000-1-3'
这种形才可以的,
你只想要年和月,是吧,
那就从2000-7-1到2000-8-1好了
时间方面的赋值我已经确定没错了,但你的代码中
select count(*)
sum(iif(是否已付='已付',1,0)) as 已付,
sum(iif(是否已付='未付',1,0)) as 未付系统提示‘sum(iif(是否已付='已付',1,0)) as 已付,’附近有语法错误呀!