I try to make a query, so that I can see who is the top customer in a month (every month since begin till now).
Now I have the tables:
orders (orderID
, orderdate
, customerID
, Netamount
, tax
, totalamount
)
orderline (orderlineID
, orderID
, prodID
, quantity
, orderdate
)
customer (firstname
lastname
zip
creditcardtype
etc.)
I think the other tables aren't necessarily here.
Of course there are customers who never bought a thing and customers who already bought plenty of times.
Now I used this query:
SELECT customerid, Sum(netamount)
FROM orders
GROUP BY customerid limit 1000000;
Now I see all customers who already bought sth. with the total amount they paid.
With the query
SELECT YEAR ( Orderdate ) Year ,
MONTHNAME ( Orderdate ) Month ,
COUNT(*) TotOrd ,
FROM orders
GROUP BY YEAR ( Orderdate ),
MONTH ( Orderdate );
I get a table where each row shows me the Yea
r Month
Total order
(placed in that month).
Still I want just to see the Top Customer of a month.
I searched a lot in the internet still couldn't find that what I want (maybe I just googled wrong). I know that I need at least one inline view still no idea how to realize it.
Hope someone can help me out here.