Solved

Query for top customer where total sales is maximum with paid

Posted on 2014-03-30
1
331 Views
Last Modified: 2014-03-30
trying to select a query which will display

eg. Select TOP 5 customers where

      - the totalamount is max , depending of the status = 'paid' of each invoice

and also the worst customer , totalamount min, and COUNT(*) where status='pending' or status = NULL
0
Comment
Question by:doramail05
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 13

Accepted Solution

by:
Koen Van Wielink earned 500 total points
ID: 39965760
For the top 5:

Select top 5 yourCustomerId, sum(totalAmount) as 'Amount'
from yourTable
Where invoiceStatus = 'Paid'
Order by sum(totalAmount) desc

The other queries work in a similar manner, just change your conditions in the where clause. For the top 5 min, change the sort order on sum(totalAmount) by removing "desc".
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

627 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