分组查询

           
                      select  cm.heatno,cm.lotheatno,cm.heatorder
                     ,max(cm.cutdate)cutdate,cm.cutdimensiona,cm.cutdimensionb,cm.length
                     ,sum( cm.weight/1000)weight
                     ,sum( cm.weightwgt/1000)weightwgt,count(cm.qty)qty
                        ,(case status 
                        when 20 then '待检验'
                        when 22 then '放行后暂留'
                        when 23 then '已挂订单'
                        when 24 then '已排轧'
                        when 29 then '待挂订单'
                        when 12 then '待挂订单'
                        else status 
                        end ) status
                     ,cm.qualitycode,cm.gkno,cm.spec,cm.warehouseno,cm.areano,cm.rowno,cm.ccno,cm.stdprodcode 
                     ,max(convert(nvarchar(50), cm.lastintime, 20))lastintime
                    
                     from t_gpkcmx cm where cm.status not in (29,54)      
            group by cm.heatno,cm.lotheatno,cm.heatorder,cm.cutdimensiona,cm.cutdimensionb,cm.length
            ,cm.qualitycode,cm.gkno,cm.spec,cm.warehouseno,cm.areano,cm.rowno,cm.ccno,cm.stdprodcode ,cm.status
             order by lastintime DESC

 

posted @ 2024-01-24 13:41  lixia64  阅读(3)  评论(0编辑  收藏  举报