Question: I'm Trying to Get the date , Discount , Total , Net Total ... ordered by date , the discount is showing the real amount but when I select multiple dates the total will be summed in those dates I've selected and it will be ordered by date 

```
DECLARE @pR FLOAT = (SELECT  SUM(CAST(Price AS FLOAT)) AS Price 
                     FROM Orders WHERE isPaid = 1  
                      AND PaidDate BETWEEN '8/17/2015' AND  '8/18/2015' ) ;

SELECT Orders.PaidDate 
     , @pR AS Total 
     ,sum(theorderids.Discount) As Discount
     ,(@pR - sum(theorderids.Discount)) AS [Net Total] 
From 
    (SELECT OrderId, PaidDate 
     FROM Orders 
     WHERE Orders.PaidDate BETWEEN '8/17/2015' AND'8/18/2015' 
     GROUP BY Orders.OrderId, Orders.PaidDate) AS Orders
INNER JOIN theorderids ON Orders.OrderId = theorderids.ID 
GROUP BY Orders.PaidDate ;

```

Example Data :

Row 1
 "PaidDate": "17-08-2015",
 "Total": 7388.0,
 "Discount": 38.0,
 "NetTotal": 7363.0

Row 2
 "PaidDate": "18-08-2015",
 "Total": 7388.0,
 "Discount": 2.0,
 "NetTotal": 7363.0

Answer: 
This will work.

```
 SELECT TheOrderids.PaidDate, MAX(Price) AS Total 
        ,sum(theorderids.Discount) As Discount
        ,(MAX(Price) - sum(theorderids.Discount)) AS [Net Total]
From 
    (SELECT PaidDate ,SUM(Price ) AS Price 
     FROM Orders 
         WHERE Orders.PaidDate BETWEEN '8/17/2015' AND'8/19/2015' 
         GROUP BY Orders.PaidDate
    ) AS Orders
INNER JOIN theorderids ON Orders.PaidDate = theorderids.PaidDate 
GROUP BY theorderids.PaidDate 
ORDER BY theorderids.PaidDate ;

```

[![enter image description here](https://i.stack.imgur.com/oaGD2.jpg)](https://i.stack.imgur.com/oaGD2.jpg)
Try this way

```
SELECT Orders.PaidDate 
     , @pR AS Total 
     ,sum(theorderids.Discount) As Discount
     ,(@pR - sum(theorderids.Discount)) AS [Net Total] 
From 
    (SELECT ROW_NUMBER() OVER(ORDER BY Orders.PaidDate ) AS Row, OrderId, PaidDate 
     FROM Orders 
     WHERE Orders.PaidDate BETWEEN '8/17/2015' AND'8/18/2015' 
     GROUP BY Orders.OrderId, Orders.PaidDate) AS Orders
INNER JOIN theorderids ON Orders.OrderId = theorderids.ID 
GROUP BY Orders.PaidDate ;

```