如何设置订单子句

时间:2013-09-25 07:06:35

标签: sql-server

select 
   DATENAME(MONTH,LIFTINGDATE) as [Month],
   sum(liftingbirds)[LiftingBirds],
   round(sum(totalweight),0)[Tot.Weight],
   round(sum(totalamount),0)[Tot.Amount],
   round(sum(totalweight)/sum(liftingbirds),2)[Avg.Weight],
   Round(Sum(Totalamount)/Sum(totalweight),2)[Avg.Rate] 
from k_LiftingEntryRecords 
where (liftingdate BETWEEN '2013-04-01 00:00.000' AND getdate())
group by DATENAME(MONTH,LIFTINGDATE)  order by  DATENAME(MONTH,LIFTINGDATE)

如何订购。哪里出错了o / p将像六月,四月,八月一样。 期望的操作是7月,7月,7月

3 个答案:

答案 0 :(得分:2)

 select DATENAME(MONTH,LIFTINGDATE) as [Month],sum(liftingbirds)[LiftingBirds],
   round(sum(totalweight),0)[Tot.Weight],
   round(sum(totalamount),0)[Tot.Amount],
   round(sum(totalweight)/sum(liftingbirds),2)[Avg.Weight],
   Round(Sum(Totalamount)/Sum(totalweight),2)[Avg.Rate]
   from k_LiftingEntryRecords where 
  (liftingdate BETWEEN '2013-04-01 00:00.000' AND getdate())
   group by DATENAME(MONTH,LIFTINGDATE) ,Month(liftingdate) 
   order by Month(liftingdate) 

试试这个......

答案 1 :(得分:1)

试试这个:

order by  DATEPART(MONTH,LIFTINGDATE)

答案 2 :(得分:0)

我不确定,但试试这个......

   select DATENAME(MONTH,LIFTINGDATE) as [Month],sum(liftingbirds)[LiftingBirds],round(sum(totalweight),0)[Tot.Weight],
   round(sum(totalamount),0)[Tot.Amount],round(sum(totalweight)/sum(liftingbirds),2)[Avg.Weight],
   Round(Sum(Totalamount)/Sum(totalweight),2)[Avg.Rate] from k_LiftingEntryRecords where (liftingdate BETWEEN '2013-04-01 00:00.000' AND getdate())
   group by DATENAME(MONTH,LIFTINGDATE)  order by  LIFTINGDATE