-1
I need to set up a query that brings the total sales of each month from a table called sales.SalesOrderHeader
, but I’m not getting it. In this table there is a field OrderDate
which is the date of sale and TotalDue
is the value of the sale. This is my attempt:
select a.Year, a.Month
from
(
select distinct cast(year(orderdate) as varchar) + '_' +
case when month(OrderDate) < 10 then '0' else '' end + cast(month(OrderDate)as varchar) as Year_Month,
sum(TotalDue) as Total
From sales.SalesOrderHeader
group by month(OrderDate), OrderDate
) a
group by a.Month
order by 1
Your question is misspelled. Please show the table structures so we can help you better.
– Gabriel Heguedusch
What is the structure of the tables?
– Victor Stafusa
From hitting the eye, it seems that missing select in the external query the column
Total
defined in the subquery.– bfavaretto
order by 1
- What is the purpose of this?– Victor Stafusa