SQL语句的简单问题

swordman119 2003-09-12 05:57:11
各位大侠,请教一下,在执行语句
SQL := 'Select Kind,Count(*),Sum(Money),Sum(Income) from account1 Where Date Like '''+Year+'-__-__'' Group by Kind';
我把结果用DBGrid显示出来了。
在着基础上,我想在把Sum(Money),Sum(Income)里的内容在加一次,把结果显示在同一个DBGrid里或者把结果显示到一个label里也行。
要求:
不冲掉语句SQL := 'Select Kind,Count(*),Sum(Money),Sum(Income) from account1 Where Date Like '''+Year+'-__-__'' Group by Kind';生成的结果。
不知道该怎么做,请大侠们指教一下,最好能给点关键代码。
...全文
23 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
swordman119 2003-09-17
  • 打赏
  • 举报
回复
这个还可行,不知道有没有办法用SQL语句解决呢?
IORILI 2003-09-17
  • 打赏
  • 举报
回复
下面程序实现了对不同货物进行分组统计,然后再记录的最后进行总合计.
对你有很大的参考价值

procedure heji(vsgrid:tvsflexgrid);
var
col,heji,kk,ll:integer; //col: vsgrid的列数 heji:保存合计值 kk:保存程序读取的行数之差
he:boolean;
begin
ceshi:=vsgrid.Rows-1;
he:=false;
case flag of
10..12,50..54:
begin
try
for record_flag:=conm to ceshi do
begin
if he=true then begin //为真则合计出现过
if record_flag<conm then //跳过合计
begin
he:=false;
continue; //执行下一循环 跳过本循环
end;
end;
if (vsgrid.TextMatrix[record_flag,0]<>vsgrid.TextMatrix[record_flag+1,0]) then //判断相邻纪录是否同类型
begin //不相同则:
he:=true;
vsgrid.AddItem(vsgrid.textmatrix[record_flag,0]+'合计',record_flag+1); //在record_flag处增加合计行
for col:=5 to vsgrid.Cols-1 do //循环计算要合计的字段值
begin heji:=0;
for record_flag2:=conm to record_flag do //从conm处开始计算
begin
if (trim(vsgrid.TextMatrix[0,col])='周计划') or (trim(vsgrid.TextMatrix[0,col])='上周欠产') or (trim(vsgrid.TextMatrix[0,col])='当日')
or (trim(vsgrid.TextMatrix[0,col])='累计') or (trim(vsgrid.TextMatrix[0,col])='欠产') then
begin
// if (vsgrid.TextMatrix[record_flag,6]='直供机') or (vsgrid.TextMatrix[record_flag,6]='内提机') then
heji:=strtoint(vsgrid.TextMatrix[record_flag2,col])+heji; //保存合计值
vsgrid.Select(record_flag+1,col); //
vsgrid.CellForeColor:= clwhite; //给合计换颜色
vsgrid.Text:=inttostr(heji); //给vsgrid的cell负值
vsgrid.Select(record_flag+1,11);
vsgrid.Text:=vsgrid.TextMatrix[record_flag,11];
vsgrid.Select(record_flag+1,12);
vsgrid.Text:=vsgrid.TextMatrix[record_flag,12];
end;
end;
vsgrid.Select(record_flag+1,col);
vsgrid.CellBackColor:=clhighlight;
end;
conm:=record_flag+2; //增加合计后 conm+2 跳过合计
ceshi:=vsgrid.Rows; //vsgrid增加了一行,重新负值
end;
end;
except
kk:=vsgrid.Rows-record_flag;
end; //由于当循环到最后两条记录时,record_flag+1不存在所以有一条记录无法计算,在这里处理
kk:=vsgrid.Rows-record_flag; //计算行数与比较过的行数之差
if kk>1 then ll:=1 else ll:=0;
if (record_flag+kk)=vsgrid.Rows then
begin
vsgrid.AddItem(vsgrid.textmatrix[record_flag+kk-1,0]+'合计',record_flag+kk);
for col:=5 to vsgrid.Cols-1 do
begin heji:=0;
for record_flag2:=conm to record_flag+ll do
begin
if (trim(vsgrid.TextMatrix[0,col])='周计划') or (trim(vsgrid.TextMatrix[0,col])='上周欠产') or (trim(vsgrid.TextMatrix[0,col])='当日')
or (trim(vsgrid.TextMatrix[0,col])='累计') or (trim(vsgrid.TextMatrix[0,col])='欠产') then
begin
heji:=strtoint(vsgrid.TextMatrix[record_flag2,col])+heji;
vsgrid.Select(record_flag+kk,col);
vsgrid.CellForeColor:= clwhite;
vsgrid.Text:=inttostr(heji);
vsgrid.Select(record_flag+kk,11);
vsgrid.Text:=vsgrid.TextMatrix[record_flag+kk-1,11];
vsgrid.Select(record_flag+kk,12);
vsgrid.Text:=vsgrid.TextMatrix[record_flag+kk-1,12];
end;
end;
vsgrid.Select(record_flag+kk,col);
vsgrid.CellBackColor:=clhighlight;
end;
exit;
end;
end;
end;
end;
swordman119 2003-09-17
  • 打赏
  • 举报
回复
不知道大家有没有好点的办法啊?帮忙一下啦
swordman119 2003-09-15
  • 打赏
  • 举报
回复
我的那段代码是这样的,怎么添写另外的一个SQL啊?怎么把它添到Label中啊?请大哥们帮我补全那个语句啊,谢谢了。
ADOQuery1.SQL.Clear;
Month := InputBox('Ô·Ý','ÇëÊäÈëÒª²éѯµÄÔ·ݣº','1');
SQL := 'Select Kind,Count(*),Sum(Money),Sum(Income) from account1 Where Date Like ''2003-'+Month+'-__'' Group by Kind';
ADOQuery1.SQL.Add(SQL);
ADOQuery1.Open;
swordman119 2003-09-15
  • 打赏
  • 举报
回复
自己还是没解决好....5555555
ziqing 2003-09-15
  • 打赏
  • 举报
回复
另外用一个SQL,SQL := 'Select Count(*),Sum(Money),Sum(Income) from account1
swordman119 2003-09-15
  • 打赏
  • 举报
回复
对于数据库我还不是很熟悉,指针也不是很会用啊,我是个刚学的菜鸟。:)
2353939 2003-09-15
  • 打赏
  • 举报
回复
mark
milerzhang 2003-09-15
  • 打赏
  • 举报
回复
运行完,把指针指向最后一条记录,看看是不是Sum(Money)或Sum(Money)中的一个值,因为有人和我说过,集合的纪录都在最后一条。但我也不知道有没有错,你式式看吧!
swordman119 2003-09-15
  • 打赏
  • 举报
回复
我不是很明白啊,请问大侠能说的清楚一点吗?
swordman119 2003-09-15
  • 打赏
  • 举报
回复
to Aarcon_Chen(凌霄) 确实不是我很想要的,不过也可以解决问题,就是显示的效果有点差:)
不知道有没有好点的解决办法呢?
初心2 2003-09-15
  • 打赏
  • 举报
回复
'Select Kind,Count(*),Sum(Money),Sum(Income) from account1 Where Date Like '''+Year+'-__-__'' Group by Kind
union
Select Sum(Money),Sum(Income) from account1 Where Date Like '''+Year+'-__-__''
或者
seletct r1.* ,r2.*
'Select Kind,Count(*),Sum(Money),Sum(Income) from account1 Where Date Like '''+Year+'-__-__'' Group by Kind r1,
Select Sum(Money),Sum(Income) from account1 Where Date Like '''+Year+'-__-__'' r2
估计不是你想要的
swordman119 2003-09-15
  • 打赏
  • 举报
回复
没有人吗??
cow8063 2003-09-12
  • 打赏
  • 举报
回复
另外用一个SQL,SQL := 'Select Kind,Count(*),Sum(Money),Sum(Income) from account1 Where Date Like '''+Year+'-__-__''

把分级组去掉,就可以显示在LABEL上了

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧