• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

SQL Syntax Question

I have the following sql query

select sales.customer,
sum(case when orders.dated >='01-nov-03' and orders.dated<='31-oct-04' then (orders.value) else 0 end) as sales04,
sum(case when orders.dated >='01-nov-03' and orders.dated<='31-mar-04' then (orders.value) else 0 end) as salesly,
sum(case when orders.dated >='01-nov-04' and orders.dated<='31-mar-05' then (orders.value) else 0 end) as salesty,
from sales,orders,sales.customer
where sales.customer=orders.customer
and orders.dated>='01-nov-03'
group by orders.customer,orders.dated
order by orders.customer

works fine except I get several lines per customer when I expect SQL to sum all the values...
Any ideas on where I am going wrong?

1 Solution
Hi sagarh,

Try removing the group by on orders.dated

Hope this helps,


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now