select custom-id,name,
       goods1=(select top 1 goods from 从表 
               where 从表.custom-id = 主表.custom-id),
  goods2=(select top 1 goods from 从表 
          where 从表.custom-id = 主表.custom-id 
          and 从表.goods not in(select top 1 goods
                              from 从表 
                              where 从表.custom-id = 主表.custom-id)
         )
from 主表(将忽略重复的goods字段)

解决方案 »

  1.   

    http://expert.csdn.net/Expert/topic/1130/1130384.xml?temp=8.945864E-02
    the same to you,go and look.
      

  2.   

    从主表用left join连接子表..
    然后依次输出主从表的各字段
      

  3.   

    建个临时表,插入可以了,最后在select临时表
      

  4.   

    select A.custom-id, A.name, B.goods goods1, C.goods goods2
      from 主表 as A left join 
       (select custom-id,goods from 从表 X 
         where goods = (select min(goods) from 从表 
                          where custom-id = X.custom-id)) as B
      on A.custom-id = B.custon-id left join 
       (select custom-id,goods from 从表 Y
         where goods = (select min(goods) from 从表 
                          where custom-id = Y.custom-id
                           and goods <> (select min(goods) from 从表
                                   where custom-id = Y.custom-id)) as C
      on A.custom-id = C.custon-id 
      

  5.   

    网断了半个月,今天看到各位的解答,谢谢。:Chiff(~o~) :tj_dns 的解答都是对的,也许是我把问题简化了,实际碰到的问题是:结果集中有goods1,goods2,goods3,goods4...甚至更多,但二位的解答并不具有一般性.