以下是引用hgfeng1984在2018-9-2 15:08:01的发言:
这个不行吧?第一眼看到就很奇怪。
CLOSE DATABASES
CLEAR
USE g:\sx\sx.dbf IN 0
LOCAL nFd,cFn,cSql,i,j
nFd = FCOUNT()
cFn = ""
cSql = ""
FOR i = 1 TO nFd
cSql = IIF(EMPTY(cSql),"",CHR(10) + cSql + " ; " + CHR(10) + " union all ; " + CHR(10) )
cSql = cSql + " select '" + FIELD(i) + "' as 题目 " + ",Count(" + FIELD(i) + ") as 参考人数"
cFn = ""
FOR j = 0 TO 8
cFn = IIF(EMPTY(cFn),"",cFn + " ,;"+CHR(10))
cFn = cFn + "
Sum(IIF(" + FIELD(i) + "='" + TRANSFORM(j) + "'" + ",1,0)) as F" + TRANSFORM(j)
ENDFOR
cSql = cSql + " ,; " + CHR(10) + cFn + " ; " + CHR(10) + " from sx "
ENDFOR
* ?cSql
EXECSCRIPT(cSql)