If I have the following table:
PART_NO CUSTOMER QTY
1001 JII 2
1001 MTH 3
1002 JII 7
How can I write a query to return the following:
PART_NO QTY CUST_CNT CUST_LIST
1001 5 2 JII, MTH
1002 7 1 JII
I tried the following query but it's not working:
SELECT
PART_NO,
SUM(QTY) AS QTY,
COUNT(DISTINCT CUSTOMER) AS CUST_CNT,
TRIM(TRAILING ',' FROM LISTAGG(CUSTOMER, ',') WITHIN GROUP (ORDER BY CUSTOMER)) AS CUST_LIST
FROM
table_name
GROUP BY
PART_NO
[Teradata Database] [3706] Syntax error: Data Type "CUSTOMER" does not match a Defined Type name.
I essentially want to return the PART_NO, sum of the QTY column by PART_NO, count of unique CUSTOMER, and the unique CUSTOMER values listed.