请问如何实现竖排变横排统计?
name deP sl
A1 AAA 1
A1 BBB 2
B2 CCC 1
C1 AAA 3
B3 BBB 2
变成
name AAA BBB CCC
A1 1 2 0
B2 0 0 1
C1 3 0 0
B3 0 2 0
VFP里如何实现
[解决办法]
SELECT NAME,SUM(IIF(deP='AAA',SL,0)),
SUM(IIF(deP='BBB',SL,0)),
SUM(IIF(deP='CCC',SL,0))
FROM TT GROUP BY NAME
[解决办法]
楼上的代码有点问题,修改如下
CSQL=CSQL+[,CAST(SUM(IIF(ALLTRIM(DEP)==']+ALLTRIM(DEP)+[',1,0)) AS N(2)) AS ]+ALLTRIM(DEP)+IIF(RECNO()<RECCOUNT(),[],[ FROM T GROUP BY 1 INTO CURSOR TTT])
改为:
CSQL=CSQL+[,CAST(SUM(IIF(ALLTRIM(DEP)==']+ALLTRIM(DEP)+[',SL,0)) AS N(2)) AS ]+ALLTRIM(DEP)+IIF(RECNO()<RECCOUNT(),[],[ FROM T GROUP BY 1 INTO CURSOR TTT])