I have an orders table with each row having :
- Order id
- Date the order was checked out
- Order transaction value
I am looking to group by date (yyyy-mm-dd) the transaction value for that period but I also want to return a running total for the period. If I ran this query against this months data (13 days in to November), I would expect to see a result set returned
- 13 rows, one for each day of the month,
- Transaction value of that day of the month
- Running Total for the month so far
I can get the transaction value group by date using group by but no running total. If I user over (partition), I am getting 1 row per transaction but the sum of the transaction values for the day.
Currently the code looks like this :
SELECT
left(convert(varchar(30),OrderCheckOutDate,120),10),
SUM (OrderTotalFixed)
OVER (Partition By left(convert(varchar(30),OrderCheckOutDate,120),10))
FROM
tblOrder
Where
UserExternalUserLevel = 0
And
OrderCheckOutDate > '2019-11-01'
It's as if the query is partitioning by millisecond but I thought the convert would handle this?
convert(DATE, OrderCheckOutDate)
- Jonathan Larouche