Select Cast(banji as N(10)) as banji, zifu from 源表 into cursor temp
Copy To temp.txt sdf
Use in Select('源表')
Use in Select('temp')
*-- 拆分成1+15个字段
cFlds = 'banji N(10)'
For i = 1 to 15
cFlds = cFlds + Textmerge(',f<<i>> C(1)')
EndFor
Create Cursor temp (&cFlds)
Append From temp.txt sdf
Erase temp.txt
cSql = ''
For i = 1 to 3
cName = ICase(i==1, '语文', i==2, '数学', '外语') + '老师'
For j = 1 to 5
If i == 1 and j == 1
c1 = ''
Else
c1 = ' union all'
EndIf
Text to c1 Noshow textmerge pretext 1+2+4+8
<<c1>> select '<<cName>>' 老师,f<<j+(i-1)*5>> 分数,count(*) 个数 from temp group by 老师,分数
EndText
cSql = cSql + c1
EndFor
EndFor
Text to cSql Noshow textmerge pretext 1+2+4+8
Select 老师,分数,Sum(个数) 个数 from (<<cSql>>) a group by 老师,分数
EndText
&cSql