How can I query order by date.
And the same for week, month, year...?
Without sample data I need to guess, but you want aggregations.
SELECT CAST(OrderDate as DATE), as 'Date' COUNT(*) as 'Orders', SUM(OrderPaidAmt) as 'TotalAmpunt' FROM OrderTable GROUP BY CAST(OrderDate as DATE)
For weeks or months, you need to do aggregation on
SELECT DATEPART(WEEK, OrderDate) as 'Week', COUNT(*) as 'Orders', SUM(OrderPaidAmt) as 'TotalAmpunt' FROM OrderTable WHERE YEAR(Orderdate) = YEAR(GETDATE()) GROUP BY CAST(OrderDate as DATE)
I added the
WHERE clause in the second one to only show from this year. If you want to see multiple years you need to
GROUP BY the
YEAR() value of your orderdate as well.