表txmd结构:
dw txsj xb
aaa 201201 1
bbb 201202 2
aaa 201207 2
ccc 201209 1
如何得到下表:
dw txsj是2012和xb是1的记录数作为一列 txsj是2012和xb是2的记录数作为一列
aaa 1 1
bbb 0 1
ccc 1 0
------解决方案--------------------------------------------------------
SELECT dw,SUM(IIF(LEFT(txsj,4)='2012' AND xb=1,1,0)) AS A1,
SUM(IIF(LEFT(txsj,4)='2012' AND xb=2,1,0)) AS A2
FROM TT GROUP BY DW