SQL Syntax Question

Posted on 2005-04-22
Last Modified: 2010-03-19
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?

Question by:sagarh
    1 Comment
    LVL 2

    Accepted Solution

    Hi sagarh,

    Try removing the group by on orders.dated

    Hope this helps,


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
    Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    Via a live example, show how to shrink a transaction log file down to a reasonable size.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now