I have a table 'allorders' which looks like that:
| Order_Nr | Items |
|---|---|
| O100 | 5X1 |
| O100 | 5X1 |
| O100 | 7B3 |
| O101 | 3A2 |
| O101 | 3A2 |
And i would like to get all items from one order as one string + the order number which should look like that:
| Order_Nr | OrderOverview |
|---|---|
| O100 | 2 x 5X1 1 x 7B3 |
My SQL-Query looks like that:
SELECT Order_Nr, LISTAGG(CONCAT(CONCAT(COUNT(Items), ' x '), Items), ' ') WITHIN GROUP(ORDER by Items) as OrderOverview
FROM allorders
WHERE Order_Nr = 'O100'
ORDER BY Order_Nr;
I am using Oracle 11g and I get the following error message:
ORA-00937: no groupfunction for single-group 00937. 00000 - "not a single-group group function" *Cause:
*Action:
If i don't select the Order_Nr in the SQL Query it works but i would like to see it in the result for a possible view which i would like to create in the future.
What am I missing? Does my idea not work in general? I hope I have worked up the data okayish, should nevertheless information be missing let me know.
Thanks,