So I'm running a report to see how many times 1 customer has placed an order with us. I have most of my data their email, how many times they have bought , their name, last order date and last OrderID.
What I can't figure out how to get is to get the productCode from items from that order.
The items are stored in a seperate table called Lines and are linked to the main order by OrderID.
Is there a way that if there are multplie lines per order to put ProductCodes from those lines as a comma seperated value?
Something like that
BuyerEmail | HowMany | Name | ProductCodes
--------------------------------------------
budyn@bud | 12 | Bud | 1231, 123,
This query will explain it better...:
SELECT TOP 1000
o.BuyerEMail
,COUNT(*) HowMany
,o.Name
,o2.OrderID
FROM Orders o
JOIN
(
SELECT
BuyerEmail
,MAX(OrderDate) Latest
FROM Orders
GROUP BY BuyerEmail
) l
ON o.BuyerEmail = l.BuyerEmail
JOIN Orders o2
ON l.BuyerEmail = o2.BuyerEmail
AND l.OrderDate = o2.OrderDate
WHERE Pay != 'PayPal'
GROUP BY
o.BuyerEmail
,o.Name
,l.Latest
ORDER BY
COUNT(*) DESC
Is it possible to concatenate cells? I just don't know where to get started here.
Thank you