select case when titlename like '橱柜' end as 橱柜,
       case when titlename like '地板' end as 地板,
       case when titlename like '门' end as 门,
       case when titlename like '灯饰' end as 灯饰
from
(
select b.titlename from NH_Class a right join NH_Class b on a.pkid=b.parentid where a.typeid='0'
) t未测试.

解决方案 »

  1.   

    先这样,我在看看.if object_id('pubs..tb') is not null
       drop table tb
    gocreate table tb
    (
    name varchar(20)
    )insert into tb(name) values('刨花板橱柜')
    insert into tb(name) values('防潮板橱柜')
    insert into tb(name) values('实木地板')
    insert into tb(name) values('强化木地板')
    insert into tb(name) values('大理石地板')
    insert into tb(name) values('平开门窗')
    insert into tb(name) values('推拉门窗')select case when name like '%橱柜%' then name end as 橱柜,
           case when name like '%地板%' then name end as 地板,
           case when name like '%门%'   then name end as 门,
           case when name like '%灯饰%' then name end as 灯饰
    from tbdrop table tb
    橱柜                   地板                   门                    灯饰                   
    -------------------- -------------------- -------------------- -------------------- 
    刨花板橱柜                NULL                 NULL                 NULL
    防潮板橱柜                NULL                 NULL                 NULL
    NULL                 实木地板                 NULL                 NULL
    NULL                 强化木地板                NULL                 NULL
    NULL                 大理石地板                NULL                 NULL
    NULL                 NULL                 平开门窗                 NULL
    NULL                 NULL                 推拉门窗                 NULL
      

  2.   

    pkid 主键
    addtime 存入的事件
    titlename 类名称
    imgurl 图片地址
    parentid  所属的大类 如果是0 ,则代表是一级分类,大于0,是二级分类的名字,如果某个记录的parentid和某个记录的pkid的值相等,说明这两个是一个类别,比如地板的pkid是125,而实木地板的parentid也是125,则这辆个是一个系列的。等等。
    typeid  --0、新品 1,旧的
    flagid  暂时没有用处。
    举个例子
    124 2006-12-4 14:11:23 橱柜水槽§uploadWebPath§Class/2006-12-4-14-11-2.jpg0  0 0
    125 2006-12-4 14:15:38地板 §uploadWebPath§Class/2006-12-4-14-15-3.jpg0   0 0
    126 2006-12-4 14:16:19门窗 §uploadWebPath§Class/2006-12-4-14-16-4.jpg0 0 0
    127 2006-12-4 14:17:02电器 §uploadWebPath§Class/2006-12-4-14-17-5.jpg0 0 0
    128 2006-12-4 14:17:52灯饰 §uploadWebPath§Class/2006-12-4-14-17-6.jpg0 0 0
    129 2006-12-4 14:18:43墙纸 §uploadWebPath§Class/2006-12-4-14-18-7.jpg 0 0 0
    131 2006-12-4 14:20:08油漆涂料§uploadWebPath§Class/2006-12-4-14-20-9.jpg0  0 0
    170 2006-12-6 10:20:24涂料 §uploadWebPath§Class/2006-12-6-10-20-22.jpg0 0 0
    171 2006-12-6 14:43:14实木地板§uploadWebPath§Class/2006-12-6-14-43-0.jpg125 0 0
    172 2006-12-6 14:44:05强化木地板§uploadWebPath§Class/2006-12-6-14-44-1.jpg 125 0 0
    173 2006-12-6 14:44:53大理石地板§uploadWebPath§Class/2006-12-6-14-44-0.jpg 125 0 0
    174 2006-12-6 14:46:12防水油漆§uploadWebPath§Class/2006-12-6-14-46-0.jpg131 0 0
    175 2006-12-6 14:46:34 防火油漆§uploadWebPath§Class/2006-12-6-14-46-0.jpg131 0 0
    176 2006-12-6 14:48:38金属灯饰§uploadWebPath§Class/2006-12-6-14-48-0.jpg128 0 0
    177 2006-12-6 14:48:53陶瓷灯饰§uploadWebPath§Class/2006-12-6-14-48-0.jpg128 0 0
    178 2006-12-6 14:49:06玻璃灯饰§uploadWebPath§Class/2006-12-6-14-49-0.jpg128  0 0
    179 2006-12-6 14:49:31塑料灯饰§uploadWebPath§Class/2006-12-6-14-49-0.jpg128  0 0
    180 2006-12-6 14:50:26平开门窗§uploadWebPath§Class/2006-12-6-14-50-0.jpg126  0 0
    181 2006-12-6 14:50:39推拉门窗§uploadWebPath§Class/2006-12-6-14-50-0.jpg126 0 0
      

  3.   

    --查询中的select * from b就是你的子查询
    --我只使用你上面的部分数据
    if object_id('pubs..tb') is not null
       drop table tb
    gocreate table tb
    (
    name varchar(20)
    )insert into tb(name) values('刨花板橱柜')
    insert into tb(name) values('防潮板橱柜')
    insert into tb(name) values('实木地板')
    insert into tb(name) values('强化木地板')
    insert into tb(name) values('大理石地板')
    insert into tb(name) values('平开门窗')
    insert into tb(name) values('推拉门窗')
    insert into tb(name) values('金属灯饰')
    insert into tb(name) values('陶瓷灯饰')
    insert into tb(name) values('玻璃灯饰')
    select id=identity(int,1,1) , name as '橱柜' into tb1 from 
    (select * from tb) t
    where name like '%橱柜%' 
    select id=identity(int,1,1) , name as '地板' into tb2 from 
    (select * from tb) t
    where name like '%地板%' 
    select id=identity(int,1,1) , name as '门' into tb3 from 
    (select * from tb) t
    where name like '%门%' 
    select id=identity(int,1,1) , name as '灯饰' into tb4 from 
    (select * from tb) t
    where name like '%灯饰%' select isnull(tb1.橱柜,'') 橱柜 ,
           isnull(tb2.地板,'') 地板 ,
           isnull(tb3.门,'')   门   ,
           isnull(tb4.灯饰,'') 灯饰 
    from tb1 
    full join tb2 on tb1.id=tb2.id
    full join tb3 on isnull(tb2.id,tb3.id)=tb3.id
    full join tb4 on isnull(isnull(tb2.id,tb3.id),tb4.id)=tb4.iddrop table tb,tb1,tb2,tb3,tb4橱柜                 地板                 门                   灯饰    
    -------------------- -------------------- -------------------- --------
    刨花板橱柜           实木地板             平开门窗             金属灯饰
    防潮板橱柜           强化木地板           推拉门窗             陶瓷灯饰
                         大理石地板                                玻璃灯饰(所影响的行数为 3 行)