有一Table表 三个字段:cus,mat,money
cus mat money
美国 猪肉 30000
美国 牛肉 20000
日本 猪肉 4000
越南     猪肉     55000
越南     牛肉     3000
....怎么把Table表查询显示为下面这种模式啊??Cus 猪肉 牛肉
美国 30000 20000
日本 4000 0
越南     55000   3000
....大虾们,求助了....

解决方案 »

  1.   

    SQL 数据库用case
    ACCESS用iif
      

  2.   

    用MSSQL 2000 
    楼上,能否给多点提示啊??
    好人做到底,给个完整点的答案,行不?
    谢谢了
      

  3.   


    select cus,
           sum(case when mat='猪肉' then money else 0) as '猪肉',
           sum(case when mat='牛肉' then money else 0) as '牛肉'
    from tb
    group by cus试试吧,随手写的
      

  4.   

    错了
    select cus,
           sum(case when mat='猪肉' then money else 0 end) as '猪肉',
           sum(case when mat='牛肉' then money else 0 end) as '牛肉'
    from tb
    group by cus
      

  5.   

    '假如数据是显示在msflexgrid网格中rs.Open "select * from 表1 order by cus", db, adOpenDynamic, adLockOptimistic  
    n=rs.recordcountmsflexgrid1.FormatString="< |^ cus |^ 猪肉|^牛肉" 
    msflexgrid1.rows=n+1
    msflexgrid1.cols=4rs.movefirst
    for i=1 to n+1
     msflexgrid1.TextMatrix(i, 1)=rs!cus  '国家 rs1.open "select * from 表1 where cus='"& msflexgrid1.textmatrix(i,1) &"'" and mat='猪肉'",db, adOpenDynamic, adLockOptimistic   rs2.open "select * from 表1 where cus='"& msflexgrid1.textmatrix(i,1) &"'" and mat='牛肉'",db, adOpenDynamic, adLockOptimistic   msflexgrid1.TextMatrix(i, 2)=rs!money  '猪肉价格
     msflexgrid1.TextMatrix(i, 3)=rs!money  '牛肉价格 rs.movenext
    next