0

I have the following table named Orders:

MerchantID (INT)
OrderID (VARCHAR2)
OrderAmount (INT)
CreatedDate (DATE/TIME)

I need to create a query that returns the average amount of orders per hour in the last X days per merchant.

Trying with:

SQL>
SELECT CAST(Startdate as CreatedDate) as 'StartDate',
CAST(DATEPART(Hour, StartDate) as varchar) + ':00' as 'Hour',
AVG(OrderAmount) as 'Average_OrderAmounts'
FROM ORDERS
GROUP BY CAST(Startdate as CreatedDate), DATEPART(Hour, StartDate)
ORDER BY CAST(Startdate as CreatedDate) ASC

does result in 0 results and I am not sure where is wrong.

  • Welcome to DBA.SE. It does help if you show the community what you have tried so far, and where you are encountering problems/difficulties. IT would equally help if we had some sample data, so as to play around a it. Reading up on [help] and [ask] (and maybe [mcve] ...) can give you an idea of the quality and content of questions that are expected. Currently your question doesn't have much substance and might be closed. – John K. N. Jun 21 '21 at 09:10
  • Do you have a table of all Merchants? – Charlieface Jun 21 '21 at 10:58
  • In this scenario no. I just have the IDs of them so far. – jugarugabi Jun 21 '21 at 12:03

0 Answers0