当前位置: 代码迷 >> Sql Server >> 日期期聚合函数及排序解决思路
  详细解决方案

日期期聚合函数及排序解决思路

热度:16   发布时间:2016-04-27 20:26:20.0
日期期聚合函数及排序
SQL语句如下:
Select   Max(MMFWorkID),Max(TaskID),Max(MMFname),ModeL,sum(BeginWeight),sum(EndWeight),  
sum(loss),sum(qty),max(batch),max(dept),max(editer),MAX(EDITDATE)  
from   MMFWork  
Where   1=1     and   TaskID   like   '%% '  
and   MMFName   like   '%% '   and   Model   like   '%% '  
and   Batch   like   '%% '     Group   by   ModeL   order   by   editdate   desc

去掉order   by   editdate可以运行,但是我需要对日期进行排序,

提示editdate未包含在聚合函数中,也未在group子句中

------解决方案--------------------
Select Max(MMFWorkID),Max(TaskID),Max(MMFname),ModeL,sum(BeginWeight),sum(EndWeight),
sum(loss),sum(qty),max(batch),max(dept),max(editer),MAX(EDITDATE)
from MMFWork
Where 1=1 and TaskID like '%% '
and MMFName like '%% ' and Model like '%% '
and Batch like '%% ' Group by ModeL order by MAX(EDITDATE) desc
------解决方案--------------------
Select Max(MMFWorkID),Max(TaskID),Max(MMFname),ModeL,sum(BeginWeight),sum(EndWeight),
sum(loss),sum(qty),max(batch),max(dept),max(editer),MAX(EDITDATE) editdate1
from MMFWork
Where 1=1 and TaskID like '%% '
and MMFName like '%% ' and Model like '%% '
and Batch like '%% ' Group by ModeL order by editdate1 desc
  相关解决方案