4
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就像六月,四月,八月一样来。期望的手术是 4 月 6 月 7 月

4

3 回答 3

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) 

尝试这个.....

于 2013-09-25T07:13:58.583 回答
1

Try this:

order by  DATEPART(MONTH,LIFTINGDATE)
于 2013-09-25T07:11:43.683 回答
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
于 2013-09-25T07:10:00.000 回答