I am trying to strengthen a transaction report based on a datetime range for a business that can be opened in two days, depending on shift management.
The user can select the datetime range (monthly, daily, weekly, free ...), the query that I implemented receives startDateTime and EndDateTime and returns all transactions grouped by day.
those.
DateTime Total Sales
---------------------------
10/15/2010 $2,300.38
10/16/2010 $1,780.00
10/17/2010 $4,200.22
10/20/2010 $900.66
My problem is that if the business shift is established, for example, from 05.00 to 02.00 the next day, all transactions made from midnight to 02:00 will be grouped the next day ... and so on ... the totals damaged. When a business has such a shift, it needs a report based on this shift, but without correcting the code (I use Java that calls Oracle's own queries), I cannot get the requested report.
I am wondering if there is some clever way to group these sets of transactions by datetime range using none other than Oracle.
Here is the query for the month of July:
SELECT Q1.dateFormat, NVL(Q1.sales, 0)
FROM (
SELECT to_date(to_char(tx.datetimeGMT +1/24 , 'mm-dd-yyyy'), 'mm-dd-yyyy') AS dateFormat
, NVL(SUM(tx.amount),0) AS sales
FROM Transaction tx
WHERE tx.datetimeGMT > to_date('20100801 08:59:59', 'yyyymmdd hh24:mi:ss') +1/24
AND tx.datetimeGMT < to_date('20100901 09:00:00', 'yyyymmdd hh24:mi:ss') + 1/24
GROUP BY to_date(to_char(tx.datetimeGMT +1/24 , 'mm-dd-yyyy'), 'mm-dd-yyyy')
) Q1
ORDER BY 1 DESC