I have two tables, Customer and Order.
In the Order table, I have a column called date_time that stores the date and time of an order. I also have the CustomerID.
I want to get the customers ID for the orders with the highest value from that day.
This is the query to retrieve the order with the highest amount in each day:
SELECT
MAX(order_amount) AS "Highest Day Amount",
to_char(date_time, 'dd/mm/yyyy') AS "ORDER DATE"
FROM
orders
GROUP BY
to_char(date_time, 'dd/mm/yyyy');
I need to use to_char because the date_time column contains both the date and time (for example: 19/05/2021 17:50) and if I don't use the to_char because I have more than one order in each day, it will consider the date to be different, because of the time component, and it will list two orders on that day instead of 1 order with the highest total.
And then I want to fetch the customer id from those orders, however I'm not sure how to do that.