我的表如下
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各位大侠帮忙,得出结果马上结贴

解决方案 »

  1.   

    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 
      

  2.   

      你可以用VB链接 ACCESS 数据库来记录呀..楼主看看这方面的 不难的``