有表如下
pos   point     startdate     drop
204     2       2006-12-1       2
204     2       2006-12-2       2
204     2       2006-12-3       1
204     2       2006-12-4       2
204     2       2006-12-5       2
204     2       2006-12-6       2
204     2       2006-12-7       3
204     2       2006-12-8       0
204     2       2006-12-9       5
218     3       2006-12-1       1
218     3       2006-12-2       2
218     3       2006-12-3       2
218     3       2006-12-4       0
218     3       2006-12-5       1
218     3       2006-12-6       3
218     3       2006-12-7       5
218     3       2006-12-8       3
218     3       2006-12-9       4
数据是按照pos和point分类,每天各增加一条新的记录
我想得到这样的查询结果
pos  point  2006-12-1  2006-12-2  2006-12-3 ......2006-12-9......
204    2        2         2           1                5
218    3        1         2           2                4
不知道怎么写才能实现呢?(看过一些关于行列转换的,看不太懂,请详细解释一下,先表示深深的谢意)

解决方案 »

  1.   

    case when.搜一下吧.好多的。
      

  2.   

    select pos, max(case when startdate='2006-12-1' then drop else '' end) as '2006-12-1',
    max(case when startdate='2006-12-2' then drop else '' end) as '2006-12-2',
    max(case when startdate='2006-12-3' then drop else '' end) as '2006-12-3',
    max(case when startdate='2006-12-4' then drop else '' end) as '2006-12-4',
    max(case when startdate='2006-12-5' then drop else '' end) as '2006-12-5',
    ........
    from XXXXXX
    group by pos
    楼主会了吗?
    其中 select 部分 需要用程序拼写的。
    不能这样直接写。
      

  3.   

    少了个 where 1
    楼主记得加上。