create cursor a1(cby c(10),meter_type c(10),userdefined3 c(12))
for i=1 to 2
xm='陈杰'+tran(i)
insert into a1(cby,meter_type,userdefined3) values(xm,'机械表','农村表')
insert into a1(cby,meter_type,userdefined3) values(xm,'机械表','城镇表')
insert into a1(cby,meter_type,userdefined3) values(xm,'机械表','商业表')
insert into a1(cby,meter_type,userdefined3) values(xm,'机械表','农村表') &&多加1条
insert into a1(cby,meter_type,userdefined3) values(xm,'远传表','农村表')
insert into a1(cby,meter_type,userdefined3) values(xm,'远传表','城镇表')
insert into a1(cby,meter_type,userdefined3) values(xm,'远传表','商业表')
insert into a1(cby,meter_type,userdefined3) values(xm,'流量计','农村表')
insert into a1(cby,meter_type,userdefined3) values(xm,'流量计','城镇表')
insert into a1(cby,meter_type,userdefined3) values(xm,'流量计','城镇表') &&多加1条
insert into a1(cby,meter_type,userdefined3) values(xm,'流量计','商业表')
ENDFOR
select cby 姓名,meter_type 水表类型,count(userdefined3) 数量,sum(IIF(userdefined3=='农村表',1,0)) 农村表 from a1 GROUP BY meter_type,cby ORDER BY cby
for i=1 to 2
xm='陈杰'+tran(i)
insert into a1(cby,meter_type,userdefined3) values(xm,'机械表','农村表')
insert into a1(cby,meter_type,userdefined3) values(xm,'机械表','城镇表')
insert into a1(cby,meter_type,userdefined3) values(xm,'机械表','商业表')
insert into a1(cby,meter_type,userdefined3) values(xm,'机械表','农村表') &&多加1条
insert into a1(cby,meter_type,userdefined3) values(xm,'远传表','农村表')
insert into a1(cby,meter_type,userdefined3) values(xm,'远传表','城镇表')
insert into a1(cby,meter_type,userdefined3) values(xm,'远传表','商业表')
insert into a1(cby,meter_type,userdefined3) values(xm,'流量计','农村表')
insert into a1(cby,meter_type,userdefined3) values(xm,'流量计','城镇表')
insert into a1(cby,meter_type,userdefined3) values(xm,'流量计','城镇表') &&多加1条
insert into a1(cby,meter_type,userdefined3) values(xm,'流量计','商业表')
ENDFOR
select cby 姓名,meter_type 水表类型,count(userdefined3) 数量,sum(IIF(userdefined3=='农村表',1,0)) 农村表 from a1 GROUP BY meter_type,cby ORDER BY cby