select to_char(用餐日期,'yyyy-mm') 用餐日期,种类,max(decode(职位,'干部',人数)) 干部用餐人数,max(decode(职位,'干部',价格)) 干部用餐价格,max(decode(职位,'干部',价格)) 员工用餐价格,max(decode(职位,'员工',人数)) 员工用餐人数,max(decode(职位,'干部',价格)) 员工用餐价格 from table_name group by to_char(用餐日期,'yyyy-mm'), 种类

解决方案 »

  1.   

    如果用餐日期一样:
    select a.用餐日期,a.种类,a.人数 干部用餐人数,a.价格 干部用餐价格,b.人数 员工用餐人数,b.价格 员工用餐价格
    from 用餐表 a,用餐表 b
    where a.用餐日期 = b.用餐日期
          and a.种类 = b.种类
          and a.用餐日期 = '2001/03/01'
          and a.种类 = '中餐'
          and a.职位 = '干部'
          and b.职位 = '员工'