日期:2014-05-19  浏览次数:20495 次

日期期聚合函数及排序
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