ksh
0601
0603
0612
0613
0614
第二张表y 各个字段里的数据很多,只列出几个出来
ksh cj
0601001 100
0601023 50
0603002 40
0612123 80
0613222 55
0614552 33
第三张表z cjzj(成绩总计) 统计所有属于0601 的总成绩,0603的总成绩 0612的总成绩等等
ksh cjzj
0601
等等。。。
请大神帮助
4 个解决方案
#1
Select Left(ksh,4) as ksh, Sum(cj) as cjzj from y group by 1 into cursor z
browse
browse
#2
如果 x 中有,y 中没有的也要列出来,则:
Select x.ksh, Sum(y.cj) as cjzj ;
from x ;
left join y on x.ksh == Left(y.ksh, 4) ;
group by 1 into cursor z
Select x.ksh, Sum(y.cj) as cjzj ;
from x ;
left join y on x.ksh == Left(y.ksh, 4) ;
group by 1 into cursor z
#3
Create Cursor 表X (Ksh C(4))
Insert Into 表X Values ("0601")
Insert Into 表X Values ("0603")
Insert Into 表X Values ("0612")
Insert Into 表X Values ("0613")
Insert Into 表X Values ("0614")
Create Cursor 表Y (Ksh C(7),Cj N(3))
Insert Into 表Y Values ("0601001",100)
Insert Into 表Y Values ("0601023",50)
Insert Into 表Y Values ("0603002",40)
Insert Into 表Y Values ("0612123",80)
Insert Into 表Y Values ("0613222",55)
Insert Into 表Y Values ("0614552",33)
Select A.Ksh,B.成绩 From 表X A Inner Join (Select Left(Ksh,4) Ksh,Sum(Cj) 成绩 From 表Y Group By 1) B On A.Ksh==B.Ksh Into Cursor 表Z
#4
VFP 默认是不精确匹配(SET ANSI OFF ),所以只需
select x.ksh, sum(y.cj) as cjzj from x, y where x.ksh=y.ksh group by 1
如果设置了精确匹配(SET ANSI ON )则
select x.ksh, sum(y.cj) as cjzj from x, y where x.ksh=LEFT(y.ksh,4) group by 1
select x.ksh, sum(y.cj) as cjzj from x, y where x.ksh=y.ksh group by 1
如果设置了精确匹配(SET ANSI ON )则
select x.ksh, sum(y.cj) as cjzj from x, y where x.ksh=LEFT(y.ksh,4) group by 1
#1
Select Left(ksh,4) as ksh, Sum(cj) as cjzj from y group by 1 into cursor z
browse
browse
#2
如果 x 中有,y 中没有的也要列出来,则:
Select x.ksh, Sum(y.cj) as cjzj ;
from x ;
left join y on x.ksh == Left(y.ksh, 4) ;
group by 1 into cursor z
Select x.ksh, Sum(y.cj) as cjzj ;
from x ;
left join y on x.ksh == Left(y.ksh, 4) ;
group by 1 into cursor z
#3
Create Cursor 表X (Ksh C(4))
Insert Into 表X Values ("0601")
Insert Into 表X Values ("0603")
Insert Into 表X Values ("0612")
Insert Into 表X Values ("0613")
Insert Into 表X Values ("0614")
Create Cursor 表Y (Ksh C(7),Cj N(3))
Insert Into 表Y Values ("0601001",100)
Insert Into 表Y Values ("0601023",50)
Insert Into 表Y Values ("0603002",40)
Insert Into 表Y Values ("0612123",80)
Insert Into 表Y Values ("0613222",55)
Insert Into 表Y Values ("0614552",33)
Select A.Ksh,B.成绩 From 表X A Inner Join (Select Left(Ksh,4) Ksh,Sum(Cj) 成绩 From 表Y Group By 1) B On A.Ksh==B.Ksh Into Cursor 表Z
#4
VFP 默认是不精确匹配(SET ANSI OFF ),所以只需
select x.ksh, sum(y.cj) as cjzj from x, y where x.ksh=y.ksh group by 1
如果设置了精确匹配(SET ANSI ON )则
select x.ksh, sum(y.cj) as cjzj from x, y where x.ksh=LEFT(y.ksh,4) group by 1
select x.ksh, sum(y.cj) as cjzj from x, y where x.ksh=y.ksh group by 1
如果设置了精确匹配(SET ANSI ON )则
select x.ksh, sum(y.cj) as cjzj from x, y where x.ksh=LEFT(y.ksh,4) group by 1