我想做一个销量排行的动态更新表,之前建立过一个商品表了,现在要做商品的排行,请问该怎么实现呢?用不用新建一个表,然后再做降序排列呢,求各位老师指导

解决方案 »

  1.   

     select       a.SN_PROID as snProId,
                    a.NAME as name,
                    a.IMG_SURL as imgSUrl,
         cast(g.ORIGINAL_PRICE/100 as decimal(8,2)) as orignalPrice,
         cast(g.PRESENT_PRICE/100 as decimal(8,2))as presentPrice,
                    a.GOODS_TITLE as goodsTitel,
                    c.SALE_COUNT as saleCount,
                    c.IS_GOOD as isGood,
                    a.DOWN_TIME as endTime,
                    a.TITLE_PREFIX as titlePrefix,
                    a.PRESENT_PRICE/a.ORIGINAL_PRICE*10 as zhekou,
                      cast((a.ORIGINAL_PRICE/100 - a.PRESENT_PRICE/100) as decimal(8,2))  as save,    from VGS_GP_GOODS a ,VGS_GP_GOODS_EXT c 
        where  exists(select sn_proid from VGS_GP_GOODS_DISTRICT b 
              where 1=1
              <#if cityId ? exists> and b.DISTRICT_LV1_ID=:cityId</#if>
              <#if areaId ? exists> and b.DISTRICT_LV2_ID =:areaId</#if>
              <#if businessId ? exists> and b.DISTRICT_LV3_ID=:businessId</#if>
               and a.SN_PROID=b.SN_PROID)          and a.SN_PROID=c.SN_PROID
                <#if category ? exists> and a.CATALOG_LV1_ID=:category</#if>
              <#if subCategory ? exists> and a.CATALOG_LV2_ID=:subCategory</#if>
              <#if isGood ? exists> and c.IS_GOOD=:isGood</#if>
              
              <#if ! sortType ? exists>order by c.SORT_KEY  </#if>
              <#if sortType ? exists && sortType=="1">order by c.SALE_COUNT desc </#if>
              <#if sortType ? exists && sortType=="2">order by a.UP_TIME  </#if>
              <#if sortType ? exists && sortType=="3">order by a.UP_TIME  DESC </#if>
              <#if sortType ? exists && sortType=="4">order by a.PRESENT_PRICE   </#if>
              <#if sortType ? exists && sortType=="5">order by a.PRESENT_PRICE  DESC </#if>不用心建表,直接查就可以了 这是我目前项目写的 你也可以直接建立一个job  让他定时跑
      

  2.   

    不知道你的商品表里有没有”销量“字段,从数据库设计来说应该不会出现在商品表的,它只是记录商品信息的;
    如果没有的话那就需要一张销量表了,每售出一件商品就更新销量表,销量排行就根据“销量排序了”,界面可采用ajax
      

  3.   

    如果你商品表没有“销量”字段,那就需要一张销量表了,每售出一件商品是更新销量表,根据销量排序,界面采用ajax
      

  4.   

    1、需要字段记录销量,不一定要单独建立销量表
    2、售出商品,则更新该字段
    3、用ajax来实现异步加载,更新销量信息