该日期的最高账单金额总和

时间:2016-07-15 12:39:52

标签: mysql

branch_id      bill_amount_total     billdate
6               1000                 05-06-12
6               1000                 06-06-12
7               2000                  05-06-12
7               500                  06-06-12
8               700                    05-06-12
8               800                    06-06-12
6               200                    05-06-12  
7              200                    05-06-12  
8              200                    05-06-12 



SELECT branch_id, sum(bill_amount_total) as max_amount,bill_date
    FROM pos_master 
    group by bill_date order by max_amount desc

我需要特定日期的最大账单金额总和

2 个答案:

答案 0 :(得分:0)

你可以试试这个:

SELECT branch_id,bill_date,max(max_amount,bill_date) FROM (
 SELECT 
   branch_id,
   bill_date,
   sum(bill_amount_total) as max_amount,bill_date
 FROM pos_master group by bill_date order by max_amount desc ) as x
GROUP BY bill_date having bill_date between '2012-06-05' and '2012-06-07' ;

答案 1 :(得分:-1)

你可以尝试以下方法

我添加了样本日期和表格

SELECT SUM(Total) FROM Orders

WHERE OrderDate BETWEEN ‘3/1'2014' AND ‘3/31/2014'