select m.BigClassName , n.* from 类别表 m,
(
  select t.* from 商品表 t where where IsHot = 1 and AddTime in (select top 4 AddTime from 商品表 where IsHot = 1 and BigClassId = t.BigClassId)
) n
where m.BigClassId = n.BigClassId
order m.BigClassId , n.AddTime desc

解决方案 »

  1.   

    --上面多了个where
    select m.BigClassName , n.* from 类别表 m,
    (
      select t.* from 商品表 t where IsHot = 1 and AddTime in (select top 4 AddTime from 商品表 where IsHot = 1 and BigClassId = t.BigClassId)
    ) n
    where m.BigClassId = n.BigClassId
    order m.BigClassId , n.AddTime desc
      

  2.   

    select a.*,b.bigclassname
    from 商品表 a,类别表 b
    where a.bigclassid=b.bigclassid and a.productid in 
    (select top 4 productid from 商品表 c 
     where a.bigclassid=c.bigclassid and c.ishot=1 order by c.bigclassid,c.addtime desc)
    order by a.bigclassid,a.addtime
      

  3.   


    --上面多了个where
    select m.BigClassName , n.* from 类别表 m,
    (
      select t.* from 商品表 t where IsHot = 1 and exists(select top 4 * from 商品表 where IsHot = 1 and BigClassId = t.BigClassId)
    ) n
    where m.BigClassId = n.BigClassId
    order m.BigClassId , n.AddTime desc
    exists的效率比in 要高