您的位置:程序门 -> vb -> 数据库(包含打印,安装,报表)



一般复杂问题,30分,得到结果立马结贴


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


一般复杂问题,30分,得到结果立马结贴[已结贴,结贴人:zuoxingyu]
发表于:2008-01-08 23:16:32 楼主
我的表如下
date1     dealflag       stimes       smoneys
1               1                         1               2.5
1               2                         1               3
1               3                         2               5
2               2                         1               2.5
2               3                         3               10
数据基本如上,其中date1是日期,每个月的哪天,dealfalg是早,中,晚餐,stimes是消费次数,smoneys是消费总金额
我现在想得到这样一个记录集
日期           早餐                     次数           金额               中餐           次数       金额       晚餐     次数     金额
1               1                         1               2.5             2               1           3           3         2         5
2               1                         0                 0               2               1           2.5       3         3         10

各位大侠帮忙,得出结果马上结贴
发表于:2008-01-09 19:06:161楼 得分:30
select  
date1   as   日期,
1   as   早餐,
sum(case   dealflag   when   1   then   stimes   else   0   end)   as   次数,
sum(case   dealflag   when   1   then   smoneys   else   0   end)   as   金额,
2   as   中餐,
sum(case   dealflag   when   2   then   stimes   else   0   end)   as   次数,
sum(case   dealflag   when   2   then   smoneys   else   0   end)   as   金额,
3   as   晚餐,
sum(case   dealflag   when   3   then   stimes   else   0   end)   as   次数,
sum(case   dealflag   when   3   then   smoneys   else   0   end)   as   金额,
from   tb
group   by   date1  
发表于:2008-01-10 08:44:272楼 得分:0
马克·吐温


快速检索

最新资讯
热门点击