create database test<br><br>use test<br>create table help1(<br> [Id] varchar(10) Default '',<br> [WorkFlow] varchar(10) Default '',<br> Quantity numeric(18, 0) Default 0,<br> [Date] datetime Default GetDate() <br>)<br><br>select * from help1<br><br>--insert help1 values('ds1080', '钻孔', '555', '2005-1-1');<br>--insert help1 values('ds1080', '生产', '816', '2005-1-1');<br>--insert help1 values('ds1080', '目视', '223', '2005-1-1');<br>--insert help1 values('ds222', '生产', '25', '2005-1-2');<br>--insert help1 values('ds222', '钻孔', '66', '2005-1-2');<br>select Id '编号', '钻孔'=max(case workFlow when '钻孔' then Quantity end),<br> '生产'=max(case workFlow when '生产' then Quantity end),<br> '目视'=max(case workFlow when '目视' then isnull(Quantity,0) end),<br> [date] '日期'<br>From help1 <br>group by id, date<br><br>自己再调整一下, 如果工序是动态的话, 自己修改一下