首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

关于Oracle数据库查询有关问题

2012-09-08 
关于Oracle数据库查询问题我有一张表(t_saleloginfo),有字段salenum(售出总数量),salemoney(总金额),Isgro

关于Oracle数据库查询问题
我有一张表(t_saleloginfo),有字段salenum(售出总数量),salemoney(总金额),Isgroup(是否团体【0:个人,1:团体】),Paytype(支付方式【0:现金,1:支票】),OfficeID(售票点编号)。我的问题是,我现在想要分别查出{票类型是个人,支付方式为现金}的各个售票点的总数量和总金额,{售票类型为团体,支付方式为个人}的各个售票点的总数量和总金额,{票类型是个人,支付方式为支票}的各个售票点的总数量和总金额,{票类型是团体,支付方式为支票}的各个售票点的总数量和总金额,然后把所查询出来的数据显示到一张表里。表结构如下

OfficeID(售票点),XGSaleNum(现金个人总数),XGSaleMoney(现金个人总金额)..........共九个字段的值。
请各位大侠积极发言。在线等待........

[解决办法]

SQL code
selectOfficeID,sum(case when Isgroup=0 and Paytype=0 then salenum else 0 end) XGSaleNum,sum(case when Isgroup=0 and Paytype=0 then salemoney else 0 end) XGSaleMoney,sum(case when Isgroup=1 and Paytype=0 then salenum else 0 end) 现金团体总数,sum(case when Isgroup=1 and Paytype=0 then salemoney else 0 end) 现金团体金额,sum(case when Isgroup=0 and Paytype=1 then salenum else 0 end) 支票个人总数,sum(case when Isgroup=0 and Paytype=1 then salemoney else 0 end) 支票个人总金额,sum(case when Isgroup=1 and Paytype=1 then salenum else 0 end) 支票团体总数,sum(case when Isgroup=1 and Paytype=1 then salemoney else 0 end) 支票团体金额from t_saleloginfogroup by OfficeID 

热点排行